Android material design buttons - Pre lollipop

后端 未结 8 2044

How do I implement the \"raised button\" and the \"flat button\" as described in google\'s material design guidelines?


Raised buttons add dimension

相关标签:
8条回答
  • 2021-01-29 20:22

    You may also need to add a bottom margin to your button, in order to be able to see the raised-button shadow effect:

    <item name="android:layout_marginBottom">@dimen/activity_vertical_margin</item>
    <item name="android:elevation">1dp</item>
    
    0 讨论(0)
  • 2021-01-29 20:23

    I use this as a background for a button with AppCompat and it depicts a raised button (with ripples n all), hope it helps.

    myRaisedButton.xml - inside the drawable folder:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                   android:shape="rectangle">
                <solid android:color="@color/yourColor"/>
                <corners android:radius="6dp"/>
            </shape>
        </item>
        <item android:drawable="?android:selectableItemBackground"/>
    </layer-list>
    

    styles.xml:

    <resources>
    
        <style name="AppTheme" parent="AppTheme.Base"/>
        <style name="AppTheme.Base" parent="Theme.AppCompat">
    
    </resources>
    

    styles.xml (v21):

    ...
    <style name="AppTheme" parent="AppTheme.Base">
    

    layout.xml:

    ...
    android:background="@drawable/myRaisedButton"
    
    0 讨论(0)
提交回复
热议问题