I am trying to change the color of the Switch
Thumb, I have created following drawable
file.
<item android:state_enabled="false" android:drawable="@color/backgroundTheme" />
<item android:state_pressed="true" android:drawable="@color/backgroundTheme" />
<item android:state_checked="true" android:drawable="@color/backgroundTheme" />
<item android:drawable="@color/backgroundTheme" />
When i add the above drawable
in my switch, it disables the switch from the layout preview. Although the switch is still there, but its not visible after adding drawable
as Thumb.
If i add an image
instead of drawable-resourse-file
, it works and display image instead of round circle.
<Switch
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/switchNotifications"
android:layout_centerHorizontal="true"
android:paddingTop="150dp"
android:text="@string/notification_settings"
android:textColor="@color/white"
android:checked="true"
android:thumb="@drawable/switch_thumb"
/>
Update
Switch_thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/gray_background" />
<item android:state_pressed="true" android:color="@color/gray_background" />
<item android:state_checked="true" android:color="@color/gray_background" />
<item android:color="@color/gray_background" />
</selector>
Following image illustrate result i am getting in my layout
I am using android:thumb
, because app:thumb gives me following error message.
Update 2
I am getting following error message, when using app:thumbTint`
Error:(31) No resource identifier found for attribute 'thumbTint' in package 'com.' Error:Execution failed for task ':app:processArmeabi-v7aDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Kirmani\AppData\Local\Android\Sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1