改变形状的颜色在Android XML形状、颜色、XML、Android

由网友(王的风范)分享简介:我有Android的绘制,我要申请的几个TextViews背景I have android drawable that I'm going to apply to the background of several TextViews我有Android的绘制,我要申请的几个TextViews背景

I have android drawable that I'm going to apply to the background of several TextViews

<?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item> 
    <shape android:shape="rectangle">
      <solid android:color="#000000" /> 
    </shape>
  </item>   

    <item android:id="@+id/clr"
        android:left="0.5dp" android:right="0.5dp"  android:top="0.5dp" android:bottom="0.5dp" >  
     <shape android:shape="rectangle"> 
      <solid android:color="#FFF000" />
    </shape>
   </item>    
 </layer-list>

我要编程上改变这种颜色。我该怎么办呢?

I want to change the color of this programmatically. How can I do that?

推荐答案

这是可能做到像这样

LayerDrawable layers = (LayerDrawable) cellLabel.getBackground();
GradientDrawable shape = (GradientDrawable) (layers.findDrawableByLayerId(R.id.clr));
shape.setColor(my_color);
阅读全文

相关推荐

最新文章