我有一个拒绝应用于活动的主题--没有应用任何样式。如果我没有为<Button>
提供layout_width
/layout_height
属性,它也会得到一个运行时错误,显示没有应用Button
类。
/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">
我漏掉的明显的错误是什么?
发布于 2012-11-19 03:51:32
我也一直在努力解决这个问题,我想我终于找到了问题所在--也许是一样的。
我在res\values
文件夹中定义了自定义主题,但没有在values-v11
和values-v14
文件夹中定义。我认为这使得在一些设备(特别是我正在测试的2)中,主题不能被应用,因为它不存在。
我现在看到在我的自定义主题中设置的属性(应用于应用程序级别)生效。
发布于 2012-09-14 15:37:07
我必须显式地为每个<activity>
定义主题。
发布于 2012-09-25 17:26:54
According to this answer,似乎不可能通过样式提供layout_width
和layout_height
。当它编译时,它引发的异常是:
E/AndroidRuntime(4117): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example/com.example.MainActivity}:
java.lang.RuntimeException: Binary XML file line #79: You must supply a
layout_width attribute.
我不确定为什么会这样,但可能会有解决办法。As this question suggests,则可以提供一个引用作为宽度和高度参数。
同样,我的经验是Android不能正确地支持通过样式提供小部件尺寸。
https://stackoverflow.com/questions/4947720
复制相似问题