2017-06-12 150 views
-1


我需要使带动态颜色的圆角背景制作TextView。
我知道如何绘制背景,但我不知道如何改变代码中的颜色?android:带有动态背景颜色的圆角背景的TextView

提拉BG 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="عمل" 
      android:textColor="#fff" 
      android:layout_marginEnd="10dp" 
      android:textSize="12sp" /> 
在Java文件中的代码

<?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> 


在布局XML TextView的

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)的颜色,

回答

1
v.setBackgroundColor(0xFF00FF00); 

试试这个(其中0xFF00FF00是颜色代码),在你想改变它, 如果你想要一些时间,你可以设置定时器或使用GIF

后更改条件而改变颜色的Java代码
+0

我曾尝试过,它删除可绘制的背景,然后改变视图的颜色(没有可绘制的背景)。 –

+0

你想绘制背景以及背景颜色?如何在同一时间在一个地方聚集两件东西 –

+0

我只需要在代码 –