在 Android 中更改整个项目中的按钮背景颜色

Change button background color in entire project in Android

我正在制作一个 Android 应用程序,但我无法更改项目中所有按钮的默认背景颜色。

我唯一能做到的就是一个一个地改变它们。

还有其他方法吗?

在主题中设置 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" >