Android 忽略样式 XML 后台指令
Android ignoring Style XML Background instruction
我想创建一个橙色按钮样式,我将 style.xml 文件放置如下:
<style name="Button">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">16sp</item>
</style>
<style name="Button.OrangeButton">
<item name="android:colorBackground">@drawable/orange_button</item>
<item name="android:textColor">@color/white</item>
</style>
然后我将样式分配给 Button,如下所示:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Broadcast"
android:id="@+id/start_broadcast_button"
android:layout_centerInParent="true"
android:theme="@style/Button.OrangeButton"
android:layout_marginTop="20dp"
/>
但是,样式说明不会传递给按钮 - 它保留默认按钮格式。
我做错了什么?
改变
android:theme="@style/Button.OrangeButton"
至
style="@style/Button.OrangeButton"
根据 Sparta 提供的答案,随着从 android:theme
到 style
的更改,您需要更改
<item name="android:colorBackground">@drawable/orange_button</item>
到
<item name="android:background">@drawable/orange_button</item>
我想创建一个橙色按钮样式,我将 style.xml 文件放置如下:
<style name="Button">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">16sp</item>
</style>
<style name="Button.OrangeButton">
<item name="android:colorBackground">@drawable/orange_button</item>
<item name="android:textColor">@color/white</item>
</style>
然后我将样式分配给 Button,如下所示:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Broadcast"
android:id="@+id/start_broadcast_button"
android:layout_centerInParent="true"
android:theme="@style/Button.OrangeButton"
android:layout_marginTop="20dp"
/>
但是,样式说明不会传递给按钮 - 它保留默认按钮格式。
我做错了什么?
改变
android:theme="@style/Button.OrangeButton"
至
style="@style/Button.OrangeButton"
根据 Sparta 提供的答案,随着从 android:theme
到 style
的更改,您需要更改
<item name="android:colorBackground">@drawable/orange_button</item>
到
<item name="android:background">@drawable/orange_button</item>