我有一个背景圆角的textview,我尝试以编程方式更改颜色背景但它不起作用.
我的代码:
<TextView
android:id="@+id/incident_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/rounded_corner"
android:backgroundTint="@color/soft_grey"
android:clickable="true"
android:gravity="center"
android:layout_marginTop="8dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="Inc"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="visible" />
Run Code Online (Sandbox Code Playgroud)
对于我的圆角我使用此代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<corners android:radius="50dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我的java代码,我尝试这两种方法,但它不起作用:
1- ((TextView) convertView.findViewById(R.id.incident_icon)).setBackgroundColor(mainActivity.getResources().getColor(R.color.honeycombish_blue, null));
2- convertView.findViewById(R.id. incident_icon).setBackgroundResource(R.color.honeycombish_blue);
Run Code Online (Sandbox Code Playgroud)