I am trying to use the latest appcompat which was updated for material design in my app to show the switch view as displayed in Lollipop(http://android-developers.blogspot.i
I had same problem today but somehow it switchcompat worked in my sample. I think that there is problem with app style, it parent should be set to:
Theme.AppCompat
I'm not sure if this is a bug in the support library, but you have to ensure that the context for your layout inflater is a themed one.
Alternatively, you can utilize
android:theme="@style/Theme.AppCompat"
On your control
I had a custom theme in my styles.xml and I forgot to specify its parent:
name="CustomTheme.switchState" parent="Theme.AppCompat.Light"
Something like this:
custom_linear_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Hello"
android:theme="@style/CustomTheme.switchState" />
...
</LinearLayout>
style.xml
<resources>
...
name="CustomTheme.switchState" parent="Theme.AppCompat.Light">
<item name="colorControlActivated">@color/colorOne</item>
<item name="android:textOn">On</item>
<item name="android:textOff">Off</item>
</style>
...
</resources>
Seems like you've encountered https://code.google.com/p/android/issues/detail?id=78262
Copy the layout and pngs, fix the nine-patch, and you should be fine.