view在使用shape属性加圆角的同时,用代码修改其他background属性(例如颜色)不生效...

项目中一个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  }
 
 

 

 

转载于:https://www.cnblogs.com/cbx17v/p/6729059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值