if(mPatients.get(position).getUploadFlag().equals("1")){ mViewHolder.selectItem.setBackgroundResource(R.drawable.btn_null); mViewHolder.selectItem.setTextColor(UiUitls.getContent() .getResources().getColor(R.color.gray)); } else { mViewHolder.selectItem.setBackgroundResource(R.drawable.btn_blue); Resources resource = UiUitls.getContent().getResources(); ColorStateList csl = resource.getColorStateList(R.color.blue_text); if (csl != null) { mViewHolder.selectItem.setTextColor(csl); } // mViewHolder.selectItem.setTextColor(UiUitls.getContent() // .getResources().getColor(R.color.blue_text)); } 如果使用注释中的代码,就只能获取到默认的颜色 无法获取到获取焦点的颜色。blue_text.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:color="#fff"/> <!-- pressed --> <item android:state_focused="true" android:color="#00a0e9"/> <!-- focused --> <item android:color="#00a0e9"/> <!-- default --> </selector>
TextView在if else中改变字体颜色无法获取到xml里面所设置的颜色值
最新推荐文章于 2021-05-27 11:38:09 发布