最近、私が取り組んでいるアプリケーションのトグルボタンが緑色のライトインジケーターを失いました。さまざまなチュートリアルから始めて、9 つのパッチ インジケーターのセットをまとめて、それらが再び正しく機能するようにしました。唯一の問題は、次のように、テキストがインジケーターの上にあることです。
古いトグル ボタンのようにテキストを一番上に表示したいのですが、何か方法はありますか?
btn_toggle_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background" android:drawable="@android:drawable/btn_default" />
<item android:id="@+android:id/toggle" android:drawable="@drawable/btn_toggle" />
</layer-list>
私の btn_toggle.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/btn_toggle_on" />
<item android:state_checked="false" android:drawable="@drawable/btn_toggle_off" />
</selector>
私のアクティビティのトグルボタンタグ:
<ToggleButton
android:background="@drawable/btn_toggle_bg"
style="@style/OurThemeName"
android:textOff="@string/fertilizer"
android:textOn="@string/fertilizer"
android:id="@+id/toggleFertilizer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false">
</ToggleButton>
<ToggleButton
android:background="@drawable/btn_toggle_bg"
style="@style/OurThemeName"
android:textOff="@string/irrigation"
android:textOn="@string/irrigation"
android:id="@+id/toggleIrrigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false">
</ToggleButton>
themes.xmlをほとんど忘れていました:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Overwrite the ToggleButton style -->
<style name="Widget.Button.Toggle" parent="android:Widget">
<item name="android:background">@drawable/btn_toggle_bg</item>
<item name="android:textOn">On</item>
<item name="android:textOff">Off</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>
<style name="OurThemeName" parent="@android:Theme.Light">
<item name="android:buttonStyleToggle">@style/Widget.Button.Toggle</item>
<item name="android:textOn"></item>
<item name="android:textOff"></item>
</style>
</resources>