如何改变从code`固color`? [英] How to change `solid color` from the code?
本文介绍了如何改变从code`固color`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图形
在定义的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
这篇关于如何改变从code`固color`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文