【问题标题】:Android Failed to find style in current themeAndroid 无法在当前主题中找到样式
【发布时间】:2015-01-12 06:28:09
【问题描述】:

在这个简单设计的主题中,Android 无法找到 numberPickerStyle ino 并且我收到此错误:

 Failed to find 'numberPickerStyle' style in current theme

我的主题是:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.Tsms" parent="@style/Theme.AppCompat.Light">
        <item name="numberPickerStyle">@style/SampleTheme.Tsms</item>
    </style>

    <style name="SampleTheme.Tsms" parent="@style/Theme.AppCompat">
        <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
    </style>

</resources>

如何解决和解决这个问题?

【问题讨论】:

    标签: android android-theme


    【解决方案1】:

    我假设您从this StackOverflow answer 复制了您的代码。 numberPickerStyle 将是您的应用程序中定义的属性。您从答案中复制的代码不起作用。您需要在 XML 中定义一个属性才能使错误消失,但这仍然对您没有任何作用。


    您不能设置NumberPicker 的样式。 android:numberPickerStyle 是私有的(请参阅此issue)。

    很遗憾,您无法设置它的样式。样式和样式属性 对于 NumberPicker 不在公共 API 中,因此您 无法设置它们并更改默认外观。你只能选择 明暗主题之间。 source

    【讨论】:

    • 您好,先生,在创建您的主题之前,我正在阅读您的介绍链接,但我无法将我的代码更改为此。我的主题是自定义的,它不是AppTheme,那是AppCompat,如何更改以我的风格定义?你能修复我的代码吗?
    • 您需要删除 numberPickerStyle 行,因为它甚至什么都不做。
    • 哦,先生。我需要在样式中定义它。
    • 除非您将numberPickerStyle 添加为项目中的自定义属性,否则您不能这样做。请重新阅读我的答案。
    • 谢谢先生。这个问题是针对simonvt.numberpicker 模块的,他说:Requires adding a single attribute to your theme 例如:&lt;style name="SampleTheme.Light" parent="android:Theme.Light"&gt; &lt;item name="numberPickerStyle"&gt;@style/NPWidget.Holo.Light.NumberPicker&lt;/item&gt; &lt;/style&gt; &lt;item name="numberPickerStyle"&gt;@style/NPWidget.Holo.NumberPicker&lt;/item&gt;
    猜你喜欢
    • 2011-10-21
    • 2016-12-19
    • 2012-01-20
    • 2012-05-25
    • 2015-01-15
    • 2012-03-16
    • 1970-01-01
    • 2019-01-31
    • 2018-12-05
    相关资源
    最近更新 更多