Ich muss TextView mit gerundetem Hintergrund mit dynamischer Farbe machen.
Ich weiß, wie man Hintergrund zeichnet, aber ich weiß nicht, wie man die Farbe im Code ändert?Android: Wie man die Farbe des zeichnenden Hintergrundes von TextView dynamisch im Java-Code ändert
die ziehbar xml bg:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/colorPrimary"></solid>
<!-- I want to change this color dynamically in the java code -->
<corners android:radius="7dp"></corners>
</shape>
</item>
</selector>
die Textview im Layout xml:
<TextView
android:id="@+id/txt_taskTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_rounded_solid"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:text="work"
android:textColor="#fff"
android:layout_marginEnd="10dp"
android:textSize="12sp" />
in der Java-Datei Code:
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.txt_taskCategory.setText(holder.mTask._catName);
holder.txt_taskCategory.setBackgroundColor(Color.parseColor(holder.mTask._catColor));
//when i do that it remove the drawable background and just color it.
}
Was ich brauche, ist zu Ändern Sie die Farbe des Zeichenhintergrunds (nicht die Textansicht) mit "holder.mTask._catColor"