Android Change button style buttons styles

Source: Internet
Author: User

Extends:http://stackoverflow.com/questions/26346727/android-material-design-button-styles

 


I'll add my answer since I don ' t use any of the other answers provided.

With the-support Library V7, all the styles is actually already defined and ready-to-use, for the standard buttons, all O F 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"

Widget.AppCompat.Button:

Widget.AppCompat.Button.Colored:

Widget.AppCompat.Button.Borderless

Widget.AppCompat.Button.Borderless.Colored:

 
 
How to change the color

For the whole app:

The color of the UI controls (not only buttons, but also floating action buttons, checkboxes etc) are managed by the A Ttribute as colorAccent explained here. Can modify this style and apply your own color in your theme definition:

<name= "Apptheme"  parent= "Theme.AppCompat.Light.NoActionBar"      >     ... <  name= "coloraccent">@color/orange</Item > </ style >

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 St Yles 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/red</item>    <item name=" Android:textcolor "> @color/white</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 the Styles.xml theme:

<item name= "ButtonStyle" > @style/btn</item>

Where is @style/btn your button theme. This sets the button style is all of the buttons in a layout with a specific theme

Android Change button style buttons styles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.