Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # With the Support Library v7, all the styles are actually already defined and ready to use, for the standard buttons, all of these styles are available:
- style="@style/Widget.AppCompat.Button"
- style="@style/Widget.AppCompat.Button.Colored"
- style="@style/Widget.AppCompat.Button.Borderless"
- style="@style/Widget.AppCompat.Button.Borderless.Colored"
- # Step 1: Define the system colors in your style. (The buttom with above styles use accent color)
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <item name="colorPrimary">@color/colorPrimary</item>
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
- <item name="colorAccent">@color/colorAccent</item>
- </style>
- # Step 2: Define your style in the buttom
- <Button style="@style/Widget.AppCompat.Button.Colored"
- [...]
- android:text="Button"/>
- # For a specific button:
- If you need to change the style of a specific button, you can define a new style, inheriting one of the parent styles described above. In the example below I just changed the background and font colors:
- <style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
- <item name="colorButtonNormal">@color/your_color_buttom</item>
- <item name="android:textColor">@color/your_text_color</item>
- </style>
- - Then you just need to apply this new style on the button with:
- android:theme="@style/AppTheme.Button"
- - To set a default button design in a layout, add this line to the styles.xml theme:
- <item name="buttonStyle">@style/AppTheme.Button</item>
- This sets the button style for all the buttons in a layout with a specific theme
Add Comment
Please, Sign In to add comment