【问题标题】:Change the shape color in an Android XML更改 Android XML 中的形状颜色
【发布时间】:2013-12-09 04:17:39
【问题描述】:

我有 android drawable 我将应用到几个 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>

我想以编程方式更改它的颜色。我该怎么做?

【问题讨论】:

标签: android xml


【解决方案1】:

可以这样做

// "cellLabel" background colour of textview or button etc. 
LayerDrawable layers = (LayerDrawable) cellLabel.getBackground();
// drawable item id
GradientDrawable shape = (GradientDrawable) (layers.findDrawableByLayerId(R.id.clr));
shape.setColor(my_color);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2017-09-03
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多