您的位置:首页 > 移动开发 > Android开发

android 按钮的设置代码显示使用drawable

2017-08-14 17:24 393 查看
按钮Button 没有按之前   unpress.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--shape:图形,rectangle为矩形;
stoke:描边
solid:填充
corners:圆角-->
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<size android:width="100dp" />
<solid android:color="#72cb60" />
<stroke
android:width="2dp"
android:color="#dcdcdc" />

</shape>

按钮Button 按之后   press.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--shape:图形,rectangle为矩形;
stoke:描边
solid:填充
corners:圆角-->
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<size android:width="100dp" />
<solid android:color="#12cb60" />
<stroke
android:width="2dp"
android:color="#dcdcdc" />

</shape>

效果实现 button_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/press" android:state_pressed="true"></item>
<item android:drawable="@drawable/unpress"></item>

</selector>

button的实现:高度要和半圆直径一样,才能实现这样的效果
<Button
android:layout_width="100dp"
android:layout_height="40dp"
android:text="@string/app_name"
android:textSize="15dp"
android:layout_centerInParent="true"
android:background="@drawable/daorus"
/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐