巧用drawable
来源:互联网 发布:nginx https配置 编辑:程序博客网 时间:2024/06/05 03:34
用@drawable时经常用到点击、选中等状态变化时图形改变的情况,
例如
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/roundbtn"/> <item android:state_pressed="false" android:drawable="@drawable/roundbtn2"/></selector>
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dp"/> <stroke android:color="@color/colorPrimary" android:width="1dp"/> <solid android:color="@color/colorPrimary"/></shape>以上两个xml定义正常和点击两种状态下的drawable
其实可以在一个xml即可完成
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true"> <shape android:shape="rectangle"> <stroke android:width="2px" android:color="@color/gray" /> <corners android:radius="12dp" /> <solid android:color="@color/transparent" /> </shape> </item> <item> <shape android:shape="rectangle"> <stroke android:width="2px" android:color="@color/gray2" /> <corners android:radius="12dp" /> <solid android:color="@color/transparent" /> </shape> </item></selector>
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" > <shape> <stroke android:color="@color/colorPrimary" android:width="1dp"/> </shape> </item> <item android:state_checked="false" > <shape> <stroke android:color="#dae6e0" android:width="1dp"/> </shape> </item></selector>
drawable资源是非常常用的,
1、图片资源
2、stateListDrawable资源
根元素为<seclector../>,可以包含多个 <item.../>元素 该元素可指定如下属性
android:color或drawable 指定颜色或Drawable对象
android:state_xxx指定一个特定状态 active 激活 checkable 是否勾选 checked 是否已勾选 enable 等等
3、LayerDrawable资源
根元素为<layer-list...>item元素可指定如下属性
4、ShapeDrawable
5、ClipDrawable
<clip .../>
详见疯狂Android讲义第三版6.4 Page300
0 0
- 巧用drawable
- Drawable
- Drawable
- Drawable
- Drawable
- drawable
- Drawable
- Drawable
- Drawable
- Drawable
- Drawable
- android.graphics.drawable.Drawable
- android drawable Transition Drawable
- Drawable之Shape drawable
- drawable-mdpi、drawable-ldpi、drawable-hdpi区别
- drawable-mdpi、drawable-ldpi、drawable-hdpi区别
- drawable-hdpi,drawable-ldpi,drawable-mdpi区别?
- 巧用Drawable 实现Android UI 元素间距效果
- Beaglebone Black———入门之改变BB-Black的CPU频率
- 00007-----连接mini2440开发板FTP
- IEtester IE6老崩溃的解决办法
- Arif in Dhaka (First Love Part 2) [Uva 10294]
- Java之静态内部类和非静态内部类的区别
- 巧用drawable
- ExtraChm的存档位置
- 【leetcode】326. Power of Three
- iOS开发调试技巧总结(持续更新中)
- Maven、eclipse与Nexus私服配置指南
- 随笔之javamail邮件发送(阿里云企业邮箱)
- C/C++函数形参传实参时值传递、指针传递、引用传递的区别
- SQL to mongo Shell to C++
- android的sqlite数据库,跨进程写数据存在同步问题