我有一个图形
在定义的XML
。现在我需要改变纯色
从code,请你指教怎么样?
< XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:形状=矩形机器人:填充=10dp>
[固体机器人:颜色=#000000/>
<角落
机器人:bottomRightRadius =8DP
机器人:bottomLeftRadius =8DP
机器人:topLeftRadius =0dp
机器人:topRightRadius =0dp/>
< /形状>
解决方案
我用这个在我的code
GradientDrawable myGrad =(GradientDrawable)rectangle.getBackground();
myGrad.setColor(Color.BLACK);
希望这有助于:)
编辑:代替 ShapeDrawable
GradientDrawable
I have a Shape
defined in xml
. Now I need to change a solid color
from the code, could you please advice how?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#000000"/>
<corners
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
解决方案
I use this in my code
GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
myGrad.setColor(Color.BLACK);
Hope this helps :)
EDIT: for GradientDrawable
instead of ShapeDrawable