简体   繁体   English

以编程方式更改xml值

[英]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);

如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式更改 XML 中的值 - How to change a value in XML programmatically 如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml 以编程方式更改 AnimatorSet 的 ObjectAnimator 中的值 - Change Value in ObjectAnimator of AnimatorSet programmatically 用html更改XML值 - Change XML value with html 使用XSLT更改XML值 - Change XML value with XSLT 以编程方式更改JavaFX TableView Vertical ScrollBar值 - Change JavaFX TableView Vertical ScrollBar value programmatically 如何以编程方式更改样式属性值? - How to change style attribute value in programmatically? JavaFX:更改以编程方式创建的按钮的值的方法 - JavaFX: Way to change value of programmatically created buttons 如何以编程方式更改 Slider 的值? (LibGDX) - How to change the value of a Slider programmatically? (LibGDX) 如何以编程方式更改这些视图布局? 我在 xml 文件中有视图,但后来想以编程方式更改它们的大小 - How to change these views layouts programmatically? I have the views in xml file, but later want to change their size programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM