0

我想在运行时更改选择器的渐变颜色。我该如何编程??

以下是选择器的 XML。

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#ffff0000"
                android:endColor="#ffff00ff"
                android:angle="270" />
            <corners
                android:topLeftRadius="3dp"
                android:topRightRadius="3dp"/>
        </shape>
    </item>

    <item>        
        <shape>
            <gradient
                android:endColor="#ffff0d00"
                android:startColor="#ffff00d0"
                android:angle="270" />
            <corners
                android:radius="3dp" />
        </shape>
    </item>
</selector>

谢谢。

4

2 回答 2

0

试试这段代码

Drawable d = getResources().getDrawable(R.drawable.your_selector_file);
yourview.setImageDrawable(d);
于 2012-10-10T08:05:51.013 回答
0

使用 GradientDrawable。例如new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xffff0000, 0xffff00ff});

于 2012-10-10T08:19:45.207 回答