[英]Change xml value programmatically
For example, I have this code: 例如,我有以下代码:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
android:color="#000000"/>
</shape>
How can I change the value of android:color
? 如何更改
android:color
的值?
Thanks 谢谢
You can create it in runtime, then change it whenever you want: 您可以在运行时创建它,然后随时更改它:
RoundRectShape rect = new RoundRectShape(
new float[] {30,30, 30,30, 30,30, 30,30},
null,
null);
ShapeDrawable bg = new ShapeDrawable(rect);
bg.getPaint.setColor(0x99FFFFFF);
view.setBackgroundDrawable(bg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.