8
votes

I cannot override the android:switchStyle. Here's what i've done :

In folder values-v14, i have two files :

themes.xml :

<style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:switchStyle">@style/SwitchAppTheme</item>
</style>

styles.xml :

<style name="SwitchAppTheme" parent="android:Widget.Holo.Light.CompoundButton.Switch">
  <item name="android:track">@drawable/switch_track_holo_light</item>
  <item name="android:thumb">@drawable/switch_inner_holo_light</item>
</style>

I've got the following errors :

res/values-v14/styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.Light.CompoundButton.Switch'.

res/values-v14/themes.xml:5: error: Error: No resource found that matches the given name: attr 'android:switchStyle'.

I've got the same problem with NumberPicker:

themes.xml :

<item name="android:numberPickerUpButtonStyle">@style/NumberPickerButtonUpAppTheme</item>
<item name="android:numberPickerDownButtonStyle">@style/NumberPickerButtonDownAppTheme</item>
<item name="android:numberPickerStyle">@style/NumberPickerAppTheme</item>

styles.xml :

<style name="NumberPickerButtonUpAppTheme" parent="android:Widget.Holo.Light.ImageButton.NumberPickerUpButton">
    <item name="android:src">@drawable/numberpicker_up_btn_holo_light</item>
</style>

<style name="NumberPickerButtonDownAppTheme" parent="android:Widget.Holo.Light.ImageButton.NumberPickerDownButton">
    <item name="android:src">@drawable/numberpicker_down_btn_holo_light</item>
</style>

I have the following errors :

/res/values-v11/themes.xml:26: error: Error: No resource found that matches the given name: attr 'android:numberPickerStyle'.

/res/values-v11/themes.xml:25: error: Error: No resource found that matches the given name: attr 'android:numberPickerDownButtonStyle'.

/res/values-v11/themes.xml:25: error: Error: No resource found that matches the given name: attr 'android:numberPickerUpButtonStyle'.

My project use SDK 16, so it should be available... Same error in eclipse and IntelliJ.

How to extend these styles ? I can extend many others (buttonStyle, buttonStyleToggle, seekBarStyle...) in the same way...

1
Ran into the same exact issue. Looks like it was reported as a Google bug as well. code.google.com/p/android/issues/detail?id=36636Jay Soyer
Yes, i have created the bug because i'm quite sure i didn't make any mistake, but i also created this post in case of someone has any idea...Jerome VDL
You can check the public attributes by looking at android.R.attr on the docs.Jake Wharton
You are right, they are not in R.attr... damned!Jerome VDL

1 Answers

4
votes

Styles for the Switch widget are not public.

You can use android-switch-backport or SwitchCompatLibrary. They also work with Android Holo Colors

There is also an alternative for the Number Picker: Better Pickers

I hope I'm helpful.