自定义一个Xml样式:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00FFFF" /> <corners android:radius="15dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape>
其中<corners android:radius="15dp" />属性就是设置圆角
最后再把TextView的android:background属性设置成自定义的xml样式文件就可以了
android:background="@drawable/textview_style"
gradient -- 颜色渐变
startcolor 起点颜色
endcolor 终点颜色
android:angle 角度 0是从左到右,90是从下到上
solid -- 填充
stroke -- 描边
corners -- 圆角
padding -- 内容离边界的距离
TextView为圆角,并且还要动态设置其颜色值。
一开始在xml中设置background属性为自定义的圆角shape,然后在代码中使用setBackgroundColor(color)。
发现设置完后圆角就消失了,后来在网上找到解决方法
在xml中设置完shape后,在代码中动态设置
GradientDrawable myGrad = (GradientDrawable)view.getBackground();
myGrad.setColor(Color.BLACK);