2017-06-12 12 views
-1


ダイナミックカラーで丸みを帯びた背景を持つTextViewを作成する必要があります。
drawable背景を作成する方法はわかっていますが、コード内の色を変更する方法はわかりません。アンドロイド:動的背景色で丸みを帯びた背景を持つTextView

描画可能BGのXML:

<?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> 
      <corners android:radius="7dp"></corners> 
     </shape> 
    </item> 


</selector> 


のTextViewレイアウトXMLで:Javaファイルのコード内

<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="عمل" 
      android:textColor="#fff" 
      android:layout_marginEnd="10dp" 
      android:textSize="12sp" /> 

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. 


} 

私は必要なものがにあります描画可能な背景の色を変更します(Textviewではなく)。"holder.mTask._catColor"

答えて

1
v.setBackgroundColor(0xFF00FF00); 

(0xFF00FF00はカラーコードです)あなたはいくつかの時間後に変更したい場合は、タイマーを設定したり、GIF

を使用することができますあなたはそれを を変更したい条件をJavaコードで色を変更するには、このを試してみてください
+0

私はこれを試しました。描画可能な背景を削除してから、描画可能な背景なしで表示色を変更します。 –

+0

あなたは背景色だけでなく描画可能な背景も必要ですか?どのように2つのものが同時に1つの場所で一緒に来ることが可能です –

+0

私はdrawableの背景(xml)のdrawableの色をコードで変更する必要があります –

関連する問題