简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM