【问题标题】:Unable to override style switchStyle and NumberPicker in Android无法在 Android 中覆盖样式 switchStyle 和 NumberPicker
【发布时间】:2012-08-30 16:21:01
【问题描述】:

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

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

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

我有以下错误:

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

res/values-v14/themes.xml:5: error: Error: No resource found that 匹配给定名称:attr 'android:switchStyle'。

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

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

我有以下错误:

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

/res/values-v11/themes.xml:25:错误:错误:找不到资源 匹配给定名称:attr 'android:numberPickerDownButtonStyle'。

/res/values-v11/themes.xml:25:错误:错误:找不到资源 匹配给定名称:attr 'android:numberPickerUpButtonStyle'。

我的项目使用 SDK 16,所以它应该可用...在 eclipse 和 IntelliJ 中出现同样的错误。

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

【问题讨论】:

  • 遇到了同样的问题。看起来它也被报告为谷歌错误。 code.google.com/p/android/issues/detail?id=36636
  • 是的,我已经创建了这个错误,因为我很确定我没有犯任何错误,但我也创建了这篇文章以防有人有任何想法......
  • 您可以通过查看文档上的 android.R.attr 来检查公共属性。
  • 你说得对,它们不在 R.attr 中...该死的!

标签: android android-widget styles


【解决方案1】:

Switch 小部件的样式不公开。

您可以使用android-switch-backport 或SwitchCompatLibrary。 他们还与Android Holo Colors合作

号码选择器还有一个替代方案:Better Pickers

希望对你有帮助。

【讨论】:

  • 谢谢,我知道,我是 Holo Colors 的作者;)我希望谷歌能做点什么......
  • Holo Colors 的工作做得很好 :) 除了投票/给问题加注星标之外,我们无能为力。
猜你喜欢
  • 2019-05-09
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-18
  • 2012-01-18
相关资源
最近更新 更多