2016-11-28 13 views
1

Androidのスイッチの画像を変更する方法を知りたいと思います。私は、スイッチをカスタマイズして色などを変えることができることを知っていますが、スイッチに別のイメージを使用するにはどうすればいいですか?私はドロウアブルからバックグラウンドを設定しようとしましたが、スイッチはまだ見えており、私のイメージの上に表示されています。トグルボタンやイメージボタンを使うことができると私は理解していますが、私たちがスイッチにすることができれば好奇心です。Androidの切り替えスイッチの画像

+0

可能duplicaすべての問題を持っている場合は元に戻す@Jerry [どのようにカスタムスイッチボタンに?](http://stackoverflow.com/questions/23358822/how-to-custom-switch-button) – Beloo

+0

これを試してください[answer](http://stackoverflow.com/questions/) 28981164/android-switch-change-on-on-on-on-off/28981942#28981942) –

答えて

1

アンドロイドをオーバーライドします。サムとアンドロイド:スイッチのコンポーネントをトラッキングして、スイッチの画像と背景をオーバーライドします。例えばのために :drawable_switchとdrawable_bgは、セレクタはそれぞれ

<Switch 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:thumb="@drawable/drawable_switch" 
android:track="@drawable/drawable_bg" /> 

drawable_switch.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_enabled="false" android:drawable="@drawable/switch_disabled" /> 
<item android:state_pressed="true" android:drawable="@drawable/switch_pressed" /> 
<item android:state_checked="true" android:drawable="@drawable/switch_enabled" /> 
<item android:drawable="@drawable/switch_default" /> 

drawable_bg.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_enabled="false" android:drawable="@drawable/switch_bg_disabled" /> 
<item android:state_focused="true" android:drawable="@drawable/switch_bg_focused" /> 
<item android:drawable="@drawable/switch_bg_default" /> 

これを試してみて、あなたはまだ

+0

ありがとうございました!これは私のために働く。 – JerryKo

0

android:thumb属性があります。

関連する問題