android 按钮圆角

引用:http://blog.sina.com.cn/s/blog_73e890f40100vpm3.html

从网上找了好多的资料,最后自己研究加借鉴人家的经验得出的结果是最简单的,现在拿出来晒晒Android圆角按钮

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,简简单单搞定

原文地址:https://www.cnblogs.com/sode/p/2529074.html