如果我有很多TextViews作为项目标签,我想我可以将所有关于它们的常见内容提取到样式中,并且在布局中仅使用
<TextView style="@style/label" android:text="Foo"/>
<TextView style="@style/label" android:text="Bar"/>
Run Code Online (Sandbox Code Playgroud)
风格如:
<style name="label">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它在模拟器和设备上工作正常,但Android XML编辑器抱怨说"<TextView>" does not set the required layout_height attribute.
,为什么它报告此警告有什么原因?
我有一个拒绝应用于活动的主题 - 没有应用任何样式.如果我没有为它提供layout_width/ layout_height属性<Button>也会收到运行时错误,表明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>
Run Code Online (Sandbox Code Playgroud)
/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>
Run Code Online (Sandbox Code Playgroud)
和相关的清单设置:
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/Theme">
Run Code Online (Sandbox Code Playgroud)
我错过了哪个明显的错误?