我想创建一个橙色按钮样式,我将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
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"
/>
但是样式指令不会传递给按钮 - 它会保留默认按钮格式。
我做错了什么?
答案 0 :(得分:1)
更改
android:theme="@style/Button.OrangeButton"
到
style="@style/Button.OrangeButton"
答案 1 :(得分:1)
根据斯巴达提供的答案,从style
更改为<item name="android:colorBackground">@drawable/orange_button</item>
,您将需要更改
<item name="android:background">@drawable/orange_button</item>
到
{{1}}