我需要在运行时更改XML文件中的android:color
我将其用于图像按钮源
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:background="@android:color/transparent"
android:contentDescription="@string/paint"
android:src="@drawable/paint"/>
我的XML画图文件看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="1dp"
android:color="@android:color/holo_purple" />
<gradient
android:startColor="@android:color/holo_purple"
android:endColor="@android:color/holo_purple" />
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
我尝试了DOM解析器,但是在进行渐变之后,它表明不再有节点
这样尝试。希望对您有帮助。谢谢
创建一个新的xml文件并将其放在drawable中,然后将其添加到按钮作为背景
渐变文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Gradient Bg for listrow -->
<gradient
android:startColor="#f1f1f2"
android:centerColor="#e7e7e8"
android:endColor="#cfcfcf"
android:angle="270" />
</shape>
layout.xml
<Button
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/gradient"
android:text="Button Text" >
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句