一起来制作flat风格的Button吧###

  • 在dimen.xml文件中定义button的边角弧度以及阴影长度

    1
    2
    <dimen name="corner_radius">4dp</dimen>
    <dimen name="layer_padding">3dp<<dimen>
  • 在colors.xml文件中定义holo风格的蓝色

    1
    2
    3
    4
    <!-- A dark Holo shade of blue -->
    <color name="holo_blue_dark">#ff0099cc</color>
    <!-- A light Holo shade of blue -->`
    <color name="holo_blue_light">#ff33b5e5</color>

  • 在drawble目录下新建flat_btn.xml的selector文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
    <shape>
    <corners android:radius="@dimen/corner_radius" />
    <solid android:color="@color/holo_blue_dark" />
    </shape>
    </item>
    <item>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
    <shape>
    <corners android:radius="@dimen/corner_radius" />
    <solid android:color="@color/holo_blue_dark" />
    </shape>
    </item>
    <item android:bottom="@dimen/layer_padding">
    <shape android:shape="rectangle">
    <corners android:radius="@dimen/corner_radius" />
    <solid android:color="@color/holo_blue_light" />
    </shape>
    </item>
    </layer-list>
    </item>