android - Switch stops displaying after adding Thumb/Track drawables -


i added switch, wanted change color, added following in drawables.

thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_enabled="false" android:drawable="@color/black" />     <item android:state_pressed="true"  android:drawable="@color/tabaccessorybuttonselected" />     <item android:state_checked="true"  android:drawable="@color/tabaccessorybuttonselected" />  </selector> 

track.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_focused="true"  android:drawable="@color/tabaccessorybuttonselected" />  </selector> 

layout.xml

<switch     android:layout_width="200dp"     android:layout_height="200dp"     android:id="@+id/switch1"     android:layout_centerhorizontal="true"     android:paddingtop="50dp"     android:text="@string/notification_settings"     android:textcolor="@color/white"     android:thumb="@drawable/thumb"     android:track="@drawable/track"     /> 

as added this, switch has stopped displaying in layout, text still there, switch tool not there.

if remove thumb.xml , track.xml starts displaying switch.

kindly guide me doing wrong here.

thanks

i have modify try solution below.

layout.xml

<switch     android:layout_width="200dp"     android:layout_height="200dp"     android:id="@+id/switch1"     android:layout_centerhorizontal="true"     android:paddingtop="50dp"     android:text="@string/notification_settings"     android:textcolor="@color/white"     android:thumb="@drawable/thumb"     android:track="@drawable/track"     /> 

track.xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android">         <item android:state_focused="true"  android:drawable="@drawable/color_thumb" />           <item                               android:drawable="@drawable/gray_track" />       </selector> 

thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_enabled="false" android:drawable="@drawable/gray_track" />     <item android:state_pressed="true"  android:drawable="@drawable/color_thumb" />     <item android:state_checked="true"  android:drawable="@drawable/color_thumb" />     <item                               android:drawable="@drawable/gray_track" /> </selector> 

color_thumb.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">     <size android:height="40dp"  />     <gradient android:height="40dp" android:startcolor="@color/tabaccessorybuttonselected"" android:endcolor="@color/tabaccessorybuttonselected""/> </shape> 

gray_track.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">     <size android:height="40dp"  />     <gradient android:height="40dp" android:startcolor="@color/tabaccessorybuttonselected" android:endcolor="@color/tabaccessorybuttonselected"/> </shape> 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -