2011-11-05 71 views
0

我有一个textview和它的背景设置使用drawable资源。如何将属性动态分配给drawable?

<TextView 
     android:id="@+id/label1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Label1" 
     android:textColor="#FFFFFF" 
     android:background="@drawable/rounded_label" 
     android:layout_below="@id/snippet" 
     android:layout_toRightOf="@id/label" 
     android:layout_alignParentBottom="true" 
     > 

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#000000"/> 
    <corners android:radius="3px"/> 
    <padding android:left="0dp" 
     android:top="0dp" android:right="0dp" 
     android:bottom="dp" /> 
</shape> 

<solid>分配颜色必须在运行时不使用XML使用代码来执行rounded_label.xml?

在此先感谢。

+1

http://stackoverflow.com/questions/ 5940825/android-change-shape-color-in-runtime 你检查过吗? – Lavanya

+0

谢谢罗莎莉,那是我需要的东西。 – siva

回答

-1

你丢失了一些

机器人:底部= “10dp”

填充值,请解决这个值。或者试试这个。

等东西, 你错了颜色设置,你必须指定4点字节的颜色,

例如:#FFFF0000

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <solid android:color="#f0600000"/> 
     <stroke android:width="3dp" color="#ffff8080"/> 
     <corners android:radius="3dp" /> 
     <padding android:left="10dp" android:top="10dp" 
      android:right="10dp" android:bottom="10dp" /> 
</shape> 
+2

是的,虽然我不确定它是否解决了这个问题:) –

+0

@Kshetri Horrorgoogle:谢谢你我会修复它。我需要在使用代码时动态地分配颜色属性。你能帮我解决这个问题。 – siva

+0

@all谢谢,我从Rosalie的评论中发现它 – siva

相关问题