改变形状的颜色在Android XML [英] Change the shape color in an Android XML

查看:135
本文介绍了改变形状的颜色在Android XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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);

这篇关于改变形状的颜色在Android XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆