【问题标题】:Change button background color in entire project in Android在Android中更改整个项目中的按钮背景颜色
【发布时间】:2016-12-20 01:58:30
【问题描述】:

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

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

还有其他方法吗?

【问题讨论】:

  • 你有几个按钮?只需复制粘贴您的 xml 文本即可获得相同的背景颜色按钮

标签: android xml button background default


【解决方案1】:

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

【讨论】:

  • 我必须对按钮的 xml 进行任何更改吗?
  • 是的,应该不需要更改按钮的。
猜你喜欢
  • 2021-03-18
  • 2021-07-05
  • 1970-01-01
  • 2015-06-04
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多