项目中一个TextView控件设置了shape属性,给其加了圆角,如下:
 houlder.mtxtGovernmentType.setBackgroundResource(R.drawable.tv_circular);
R.drawable.tv_circular的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<solid android:color="#00000000" />
</shape>
一个view只能设置一个background,每设置一次Background,另一个Background就会就会被替换掉。
所以用下面这个GradientDrawable函数来进行多个设置
 GradientDrawable myGrad = (GradientDrawable) houlder.mtxtGovernmentType.getBackground();
if (item.getStatus().equals("登记")) {
myGrad.setColor(context.getResources().getColor(R.color.theme_color_primary_light));
} else {
myGrad.setColor(context.getResources().getColor(R.color.zong));
}
 
05-11 22:52