手机卫士学习15-自定义shape图形资源
来源:互联网 发布:侠客风云传 战斗数据 编辑:程序博客网 时间:2024/05/29 19:09
自定义shape图形资源
需求:
制作一个textView按钮,默认背景为白色圆角矩形,点击textView背景变成黑色的圆角矩形。
通过查看API文档:
EXAMPLE:
This layout XML applies the shape drawable to a View:
在drawable目录下创建白色圆角矩形xml文件和黑色xml文件。
白色圆角矩形:
黑色圆角矩形:
gradient_box_presssed.xml:
TextView背景选择器:
text_selector.xml:
在TextView属性中设置:
需求:
制作一个textView按钮,默认背景为白色圆角矩形,点击textView背景变成黑色的圆角矩形。
通过查看API文档:
app Resources -->Resource Types --> Drawable --> Shape Drawable的实例代码:
XML file saved at res/drawable/gradient_box.xml
:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /></shape>
This layout XML applies the shape drawable to a View:
<TextView android:background="@drawable/gradient_box" android:layout_height="wrap_content" android:layout_width="wrap_content" />
在drawable目录下创建白色圆角矩形xml文件和黑色xml文件。
白色圆角矩形:
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="8dp" /> <solid android:color="#ffffff"/></shape>
黑色圆角矩形:
gradient_box_presssed.xml:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="8dp" /> <solid android:color="#44000000"/></shape>
TextView背景选择器:
text_selector.xml:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/gradient_box_pressed" android:state_pressed="true"/> <!-- pressed --> <item android:drawable="@drawable/gradient_box_pressed" android:state_focused="true"/> <!-- focused --> <item android:drawable="@drawable/gradient_box"/> <!-- default --></selector>
在TextView属性中设置:
android:background="@drawable/text_selector"
0 0
- 手机卫士学习15-自定义shape图形资源
- drawable自定义图形资源之shape属性
- 手机卫士学习09-自定义对话框
- 手机卫士 自定义土司
- Android 自定义图形 shape
- Shape自定义图形详解
- Android自定义图形-Shape
- 手机卫士学习13-自定义按钮状态背景
- 手机卫士学习16-Activity界面切换自定义动画
- 手机卫士05-自定义对话框
- Android自定义shape资源
- Android 自定义shape图形效果
- Android系列: 自定义图形shape
- xml之shape 自定义图形
- 安卓自定义图形shape
- 手机卫士学习22- 一键锁屏
- 手机卫士开发学习1
- 手机卫士学习05-手机卫士主界面UI
- zhcon-Ubuntu字符界面(终端tty1-6)中文乱码和分辨率的解决方案
- 【Cocos2d-x】3.3 ClippingRectangleNode与ClippingNode 以及 ClippingRectangleNode BUG
- java中使用MD5对密码进行加密
- Android权限大全
- android IPC通信中的UID和PID识别
- 手机卫士学习15-自定义shape图形资源
- 我的2014年总结——奔波的一年
- 可视分析小记——理解、分析、感悟(持续更新中)
- WV.5-动态链表-查找判断是否存在
- ubuntu 无法挂载ntfs分区-提示:不能访问**GB卷
- IOS多线程编程系类
- WEB应用开发该选择什么图片格式?
- 关于装XP“无法复制安装文件”
- 设计模式阶段性总结之对象创建