如何动态改变形状颜色? [英] How to change shape color dynamically?
本文介绍了如何动态改变形状颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFF00" />
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
</shape>
<TextView
android:background="@drawable/test"
android:layout_height="45dp"
android:layout_width="100dp"
android:text="Moderate"
/>
所以现在我想让这个形状根据我从网络服务调用中得到的信息改变颜色.所以它可能是黄色、绿色或红色或其他任何颜色,具体取决于我从网络服务电话中收到的颜色.
So now I want this shape to change colors based on information I get back from a web service call. So it could be maybe yellow or green or red or whatever depending on the color I receive from the web serivce call.
如何更改形状的颜色?基于这些信息?
How can I change the color of the shape? Based on this information?
推荐答案
你可以像这样简单地修改它
You could modify it simply like this
GradientDrawable bgShape = (GradientDrawable)btn.getBackground();
bgShape.setColor(Color.BLACK);
这篇关于如何动态改变形状颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文