Android按钮shape形状资源代码实现
2015-03-31 08:45
615 查看
1、项目Src下创建drawable
看文档Develop/API Guides/App Resources/Drawable/Shape Drawable单词:corners : 角 ; gradient :梯度; solid:固定的; stroke: 边框--可以做下划线
Rectangle : 矩形;dash :破折号 gap:间隙;
2、拷贝实例代码,文件命名(gradient_box.xml,下面是模版)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <gradient android:startColor="#ff0000" android:endColor="#00ff0000"/> <solid android:color="#ffffff" /> <stroke android:width="3dip" android:color="#000000" android:dashGap="5dip" android:dashWidth="5dip"/> </shape>
3、默认状态function_greenbutton_normal.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <solid android:color="#ffffff" /> </shape>
4、按下去状态状态function_greenbutton_pressed.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dip"/> <solid android:color="#22000000" /> </shape>
5、把两个状态整合在shape_bg.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/function_greenbutton_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/function_greenbutton_pressed" /> <!-- focused --> <item android:drawable="@drawable/function_greenbutton_normal" /> <!-- default --> </selector>
6、并使用
在Button框下android:background="@drawable/shape_bg"来调用。相关文章推荐
- android自定义ImageButton按钮的按下效果的代码实现
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。 .
- 在实际项目中实现把swf资源里面的MC进行转化成按钮,实现代码的复用
- android Button按钮实现点击效果代码附带demo下载
- Android Library 工程实现模块复用 (代码及资源文件)
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。 2014-07-04 13:17 78人阅读 评论(0) 收藏
- android中控制根据是否选中或者按下改变按钮的颜色(通过xml代码实现)
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法
- 【Android】0行代码实现任意形状图片展示--android-anyshape
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法
- 转载 :Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- Android中使用shape来实现控件形状的设置
- 通过代码实现android shape的功能
- android里面shape属性用代码实现圆角背景的工具类
- Android中ImageButton自定义按钮的按下效果的代码实现方法
- Android ImageButton自定义按钮的按下效果的代码实现方法分享
- android-代码实现XML中的shape的效果
- android select采用代码实现按钮背景
- Android点击按钮实现全屏的代码