Android碎笔录2——按键的点击变色和圆角实现
2024-08-27 23:44:42
android的Button默认写出来之后都是方形的直角,并且点击感很不明显,只要在drawable中加上一个xml就能解决这个问题:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> //点击时的样子
<shape android:shape="rectangle"> //显示为方形
<corners //显示为圆角
android:topLeftRadius="8dip"
android:topRightRadius="8dip"
android:bottomLeftRadius="8dip"
android:bottomRightRadius="8dip"/>
<solid android:color="@color/darkred"/> //背景颜色
</shape>
</item>
<item android:state_pressed="false"> //没点击时的样子
<shape android:shape="rectangle">
<corners
android:topLeftRadius="8dip"
android:topRightRadius="8dip"
android:bottomLeftRadius="8dip"
android:bottomRightRadius="8dip"/>
<solid android:color="@color/red"/>
</shape>
</item>
</selector>
我的xml命名是background_shape.xml,去掉我写的注释就直接能用,用法是在Button中加上:
android:background="@drawable/backguound_shape"
这样就能完成了。
最新文章
- [转载]IE678兼容性前缀区分
- c链表实现遇到的错误
- Unity3D在Windows的全屏和跨屏(双屏)方案
- Xcode编译异常和警告汇总(持续更新中)
- Add LUN to ASM in Linux
- 《Code Complete》ch.11 变量名的力量
- Maven SDK
- Myeclipse配置mybatis的xml自动提示
- HTTP状态码的意义
- MySQL之表的数据类型
- CRM之分页
- Codechef Bear and Clique Distances
- roc曲线和auc
- [转载]Windows&#160;2003&#160;R2&#160;SP2&#160;VOL&#160;企业版(简体中文)
- Django路由层
- Keepalived基础知识-运维小结
- Volley 结合GSON或FastJson用法
- [UE4]蓝图:重写父类时调用父类方法
- css基础 行内元素 块级元素
- UE和UI的区别