以编程方式更改xml值

时间:2013-10-22 15:32:56

标签: java android xml

例如,我有这段代码:

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
        <stroke 
            android:width="1dip" 
            android:color="#000000"/>
</shape>

如何更改android:color的价值?

由于

1 个答案:

答案 0 :(得分:0)

您可以在运行时创建它,然后随时更改它:

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);