android 按钮圆角
引用:http://blog.sina.com.cn/s/blog_73e890f40100vpm3.html
从网上找了好多的资料,最后自己研究加借鉴人家的经验得出的结果是最简单的,现在拿出来晒晒
1.在res下新建一个drawable文件夹
2.在drawable中定义圆角按钮的文件btn1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@drawable/btn_blue"/>
<stroke android:width="1dp" color="@drawable/btn_blue"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"
/>
</shape>
3.在Activity代码中使用 或是 在xml布局文件中直接 android:background="@drawable/..."
int color=R.drawable.按钮配置文件名
Resources res=getResources();
Drawable draw=res.getDrawable(color);
btn.setBackgroundDrawable(draw);
OK,简简单单搞定
更多相关文章
- conversion to dalvik format failed with error 1 错误解决方案
- android中的资源使用
- 文件接收网络对讲机C#服务器 Android客户端(二) C#服务器代码分析
- 【Android(安卓)Developers Training】 24. 保存键值对
- Android(安卓)下载zip压缩文件并解压
- Android(安卓)手机上传图片至javaweb服务器(servlet)
- Android2.2快速入门 zz
- Android(安卓)点击两次退后按钮程序退出
- Androidstudio打包jar和arr包