Search code examples
androidxmlbuttonbackgrounddefault

Change button background color in entire project in Android


I'm making an Android app, but I cannot change the default background color of all buttons in the project.

The only way I can do it is by changing them one by one.

Is there any other way?


Solution

  • Set buttonStyle in your Theme.

    like following: (I assume that you use AppCompat)

    In your 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>
    

    In your AndroidManifest.xml:

    <application
         ...
        android:theme="@style/AppTheme" >