项目中一个TextView控件设置了shape属性,给其加了圆角,如下:
1 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函数来进行多个设置
1 GradientDrawable myGrad = (GradientDrawable) houlder.mtxtGovernmentType.getBackground();
2 if (item.getStatus().equals("登记")) {
3      myGrad.setColor(context.getResources().getColor(R.color.theme_color_primary_light));
4 } else {
5      myGrad.setColor(context.getResources().getColor(R.color.zong));
6  }

 

 

相关文章:

  • 2022-12-23
  • 2021-10-06
  • 2022-03-08
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2021-06-24
  • 2021-05-28
  • 2021-08-24
  • 2021-11-30
  • 2021-05-12
相关资源
相似解决方案