• Material Design Button 样式



    132down voteaccepted

    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


    To answer the question, the style to use is therefore style="@style/Widget.AppCompat.Button.Colored".


    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"
  • 相关阅读:
    MapReduce in MongoDB
    MongoDB的一些基本操作
    谈谈NOSQL
    Java中的反射(1)
    Mybatisの常见面试题
    关于Lombok和自动生成get set方法
    订Pizza(Java)
    美化Div的边框
    爱,死亡和机器人(Love,Death&Robots)
    session与cookie的介绍和两者的区别之其相互的关系
  • 原文地址:https://www.cnblogs.com/qianyukun/p/5854021.html
Copyright © 2020-2023  润新知