zoukankan      html  css  js  c++  java
  • Android 更改按钮样式 Button Styles

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

     


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

    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"
    

    Widget.AppCompat.Buttonenter image description here

    Widget.AppCompat.Button.Coloredenter image description here

    Widget.AppCompat.Button.Borderless enter image description here

    Widget.AppCompat.Button.Borderless.Coloredenter image description here

     
      

    How to change the color

    For the whole app:

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

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <item 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 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/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 this line to the styles.xml theme:

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

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

  • 相关阅读:
    2020牛客寒假算法基础集训营4-I 匹配星星【贪心】
    P1880 [NOI1995]石子合并【区间dp】
    P1280 尼克的任务
    P1041 传染病控制【暴搜】
    Heavy Transportation POJ
    【空间】C++内存管理
    【编译器】G++常用命令
    【NOIP2011】【Luogu1003】铺地毯
    【Luogu1739】表达式括号匹配
    【Luogu1160】队列安排
  • 原文地址:https://www.cnblogs.com/niray/p/6862090.html
Copyright © 2011-2022 走看看