Search code examples
javaandroidxmlstylesthemes

How to combine style into a theme?


I have created a style:

 <style name="Button_Display">
    <item name="android:minHeight">48dip</item>
    <item name="android:minWidth">88dip</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:gravity">center_vertical|center_horizontal</item>
</style>

I want that all the Button's in my application will look like declared above. My question is how can i combine the Button_Display style inside a theme so all the Buttons in my app will have this look and feel?


Solution

  • https://developer.android.com/guide/topics/ui/look-and-feel/themes

    In styles.xml create your own button style. Choose whatever parent style matches your need the best. Then overwrite all the necessary parameters.

    <style name="myButtonStyle" parent="@style/Widget.AppCompat.Button">
        <item name="android:minHeight">48dip</item>
        <item name="android:minWidth">88dip</item>
         ...
    </style>
    

    Then set this as default button style in your theme.

    <style name="AppTheme" parent="Theme.AppCompat....">
          <item name="buttonStyle">@style/myButtonStyle</item>
           ...
    </style>
    

    Now all Buttons will have the parameters you specified in your style.