Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to override style switchStyle and NumberPicker in Android

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...

like image 687
Jerome VDL Avatar asked Aug 30 '12 16:08

Jerome VDL


1 Answers

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.

like image 92
LordRaydenMK Avatar answered Sep 28 '22 00:09

LordRaydenMK