【发布时间】:2016-12-20 01:58:30
【问题描述】:
我正在制作一个 Android 应用,但我无法更改项目中所有按钮的默认背景颜色。
我能做到的唯一方法就是一个一个地改变它们。
还有其他方法吗?
【问题讨论】:
-
你有几个按钮?只需复制粘贴您的 xml 文本即可获得相同的背景颜色按钮
标签: android xml button background default
我正在制作一个 Android 应用,但我无法更改项目中所有按钮的默认背景颜色。
我能做到的唯一方法就是一个一个地改变它们。
还有其他方法吗?
【问题讨论】:
标签: android xml button background default
在您的主题中设置 buttonStyle。
如下:
(我假设你使用AppCompat)
在你的 style.xml 中:
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
...
<item name="buttonStyle">@style/YourButtonStyle</item>
<!-- For preview -->
<item name="android:buttonStyle">@style/YourButtonStyle</item>
</style>
<style name="YourButtonStyle" parent="@style/Widget.AppCompat.Button">
<!-- Set background -->
<item name="android:background">@drawable/your_button_drawable</item>
</style>
</resources>
在您的 AndroidManifest.xml 中:
<application
...
android:theme="@style/AppTheme" >
【讨论】: