How to mimic the Material-design raised button style, even for pre-Lollipop (minus the special effects)?

后端 未结 7 1922
别跟我提以往
别跟我提以往 2020-12-07 16:54

Google has shown some nice ways that buttons are shown on Lollipop here.

I\'m talking about both the raised and the flat buttons.

How can I mimic them on pre

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 17:17

    Add the compat library to your app. (The most current version can be found here.) Do this by adding a dependency within your build.gradle file:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
    }
    

    Declate your apptheme in a styles.xml file located in the values directory:

    
        
        
    
    

    Set the declared style as the one to use for your application in the manifest.xml file:

    
    

    In your layouts declare a raised button as follows

    Declare a flat button style as follows:

    Result on both a 4.4 (a phone) and a 5.0 (a tablet) device:

    Tablet with 5.0

    Phone 4.4

    Details can be found in the official documentation: http://developer.android.com/training/material/theme.html

提交回复
热议问题