Raised and flat buttons with different background and highlight colors

前端 未结 1 791
南方客
南方客 2021-01-03 11:26

I\'m creating application using com.android.support:appcompat-v7:23.0.1 library.

I define application theme in values/styles.xml:



        
相关标签:
1条回答
  • 2021-01-03 11:54

    After some research and googling I defined separate themes for different raised and flat buttons:

    <style name="AppTheme.RaisedButton">
        <item name="buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
    </style>
    
    <style name="AppTheme.RaisedButton.Primary">
        <item name="colorAccent">@color/primary</item>
    </style>
    
    <style name="AppTheme.RaisedButton.Accent">
    </style>
    
    <style name="AppTheme.FlatButton">
        <item name="buttonStyle">@style/Widget.AppCompat.Button.Borderless.Colored</item>
        <item name="colorControlHighlight">@color/highlight_light</item>
    </style>
    
    <style name="AppTheme.FlatButton.Primary">
        <item name="colorAccent">@color/primary</item>
    </style>
    
    <style name="AppTheme.FlatButton.Accent">
    </style>
    

    Note, that I'm using buttonStyle attribute not android:buttonStyle because it will not work on pre-lollipop devices.

    Use these themes in android:theme attribute:

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/my_button"
        android:theme="@style/AppTheme.FlatButton.Primary" />
    
    0 讨论(0)
提交回复
热议问题