Flat Button简单制作

Flat Button简单制作  

创建 colors.xml 文件定义两个颜色

   
   
  1. <resources>
  2. <color name="blue_pressed">@android:color/holo_blue_dark</color>
  3. <color name="blue_normal">@android:color/holo_blue_light</color>
  4. </resources>

我们这里使用android的 HOLO 色调:

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

创建 dimen.xml 文件,定义圆角值和阴影高度,见下图

   
   
  1. <resources>
  2. <dimen name="corner_radius">4dp</dimen>
  3. <dimen name="layer_padding">3dp<<dimen>
  4. </resources>
Flat Button简单制作 - gitonway - Android Dev_ Weekly

 

Flat Button简单制作 - gitonway - Android Dev_ Weekly
 

我们用shape来定义按钮背景 创建rect_pressed.xml 的 drawable 文件

   
   
  1. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:shape="rectangle">
  3. <corners android:radius="@dimen/corner_radius" />
  4. <solid android:color="@color/blue_pressed" />
  5. </shape>
Flat Button简单制作 - gitonway - Android Dev_ Weekly
 

创建rect_normal.xml file 的drawable 文件。

   
   
  1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  2. <item android:drawable="@drawable/rect_pressed" />
  3.  
  4. <item android:bottom="@dimen/layer_padding">
  5. <shape android:shape="rectangle">
  6. <corners android:radius="@dimen/corner_radius" />
  7. <solid android:color="@color/blue_normal" />
  8. </shape>
  9. </item>
  10. </layer-list>
Flat Button简单制作 - gitonway - Android Dev_ Weekly
 

为按钮定义 selector . 创建flat_selector.xml 文件。

   
   
  1. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  2. <item android:state_pressed="true" android:drawable="@drawable/rect_pressed"/>
  3. <item android:drawable="@drawable/rect_normal"/>
  4. </selector>

定义 button 设置 background 为 flat_selector.

   
   
  1. <Button
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:background="@drawable/flat_selector"
  5. android:textColor="@android:color/white"
  6. android:text="Say Hello" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值