未设置 Android 主题
我有一个拒绝应用于活动的主题 - 没有应用任何样式.如果我不为 <Button>
提供 layout_width
/layout_height
属性,它也会出现运行时错误,显示 按钮
类没有被应用.
I have a theme that refuses to be applied to activities - none of the styles are applied. If I don't supply the layout_width
/layout_height
attributes for <Button>
it also gets a runtime error, showing that the Button
class isn't being applied.
/res/values/themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:style/Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:buttonStyle">@style/Button</item>
<item name="android:windowBackground">@color/page_background_light</item>
<item name="android:textAppearance">@style/TextAppearance</item>
</style>
</resources>
/res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextAppearance" parent="@android:style/TextAppearance">
<item name="android:textSize">12sp</item>
<item name="android:textColor">@color/darkblue</item>
</style>
<style name="Button" parent="@android:style/Widget.Button">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<!--<item name="android:textColor">#3C2F4F</item>
<item name="android:textSize">20dip</item>-->
</style>
</resources>
和相关的清单设置:
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/Theme">
我遗漏的明显错误是什么?
What's the obvious mistake I'm missing?
我也一直在为此苦苦挣扎,我想我终于找到了可能的问题所在——也许是一样的.
I've been struggling with this as well, and think I've finally found what may have been the problem - perhaps it is the same.
我在 resvalues
文件夹中定义了自定义主题,但在 values-v11
和 values-v14
文件夹中没有.我认为这使得在某些设备(特别是我正在测试的 2!)中,主题无法应用,因为它不存在.
I had the custom theme defined in the resvalues
folder, but not in the values-v11
and values-v14
folders. Which I think made it so that in some devices (specially the 2 I was testing with!), the theme could not be applied because it did not exist.
我现在看到在我的自定义主题中设置的属性(在应用程序级别应用)生效.
I now see the properties set in my custom theme (applied at the application level) taking effect.