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"
/>
<?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"
/>
相关文章推荐
- Android使用代码为textview设置drawableLeft或drawableRight
- Android使用Java代码设置selector或drawable,以及使用自定义控件方式使用它
- android在代码中setBackgroundDrawable设置图片显示不正常
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- android中使用afinal一行代码显示网络图片
- WordPress使用自定义字段设置缩略图和显示作者文章数量和评论数量代码
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- Android4.2设置--显示--休眠代码跟踪
- 使用代码控制Android的TextView属性drawableLeft
- android 如何使用命令和代码设置heapsize
- Android 使用XML实现按钮改变焦点设置背景图
- Android 使用代码设置系统时间
- 我的VS2005采用的是web开发设置。不知道动到了那里,现在每次按F5启动调试的时候总是不能成功启动调试。效果和按CTRL+F5一样。就是把项目显示在了浏览器之后,那个启动调试的绿色按钮还可以使用,不是暗色的。
- 使Android应用的AlertDialog对话框中的按钮显示为ImageButton图标,并设置相应
- Android对话框的高级设置《二》设置对话框按钮的透明度和对话框的在屏幕上的显示位置
- android中使用java代码设置控件获得焦点
- android webview设置缩放按钮时候无法显示问题
- 使用代码为TextView或者Button设置drawableLeft,top,ringht,buttom
- android代码设置全屏显示