无法覆盖Android中的样式switchStyle和NumberPicker

Jer*_*VDL 8 android styles android-widget

我无法覆盖android:switchStyle.这就是我所做的:

在文件夹值-v14中,我有两个文件:

themes.xml:

<style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:switchStyle">@style/SwitchAppTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

res/values-v14/styles.xml:4:错误:检索项目的父项时出错:找不到与给定名称"android:Widget.Holo.Light.CompoundButton.Switch"匹配的资源.

res/values-v14/themes.xml:5:错误:错误:找不到与给定名称匹配的资源:attr'android:switchStyle'.

我在NumberPicker遇到了同样的问题:

themes.xml:

<item name="android:numberPickerUpButtonStyle">@style/NumberPickerButtonUpAppTheme</item>
<item name="android:numberPickerDownButtonStyle">@style/NumberPickerButtonDownAppTheme</item>
<item name="android:numberPickerStyle">@style/NumberPickerAppTheme</item>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

/res/values-v11/themes.xml:26:错误:错误:找不到与给定名称匹配的资源:attr'android:numberPickerStyle'.

/res/values-v11/themes.xml:25:错误:错误:ATTR"机器人:numberPickerDownButtonStyle"没有资源发现在给定的名字相匹配.

/res/values-v11/themes.xml:25:错误:错误:ATTR"机器人:numberPickerUpButtonStyle"没有资源发现在给定的名字相匹配.

我的项目使用SDK 16,因此它应该可用...在eclipse和IntelliJ中出现相同的错误.

如何扩展这些风格?我可以用同样的方式扩展许多其他的(buttonStyle,buttonStyleToggle,seekBarStyle ......)

Lor*_*nMK 4

Switch 小部件的样式不是公开的。

您可以使用android-switch-backportSwitchCompatLibrary。它们还可以与Android Holo Colors配合使用

数字选择器还有一个替代方案:更好的选择器

我希望我能有所帮助。

  • 谢谢,我知道,我是 Holo Colors 的作者;)我希望 Google 能做点什么...... (3认同)