【发布时间】:2014-06-18 15:41:48
【问题描述】:
我想以编程方式创建选择器可绘制对象。形状必须采用以下形式:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape>
<solid android:color="#4aa5d4" />
</shape></item>
<item><shape>
<stroke android:width="1dp" android:color="#4aa5d4" />
</shape></item>
</selector>
为什么?因为我希望这两种颜色是可变的。我知道我必须为此创建某种Drawable。我已经设法创建了自己的GradientDrawables,如下所示:
public GradientDrawable getBackgroundGradient() {
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { BACKGROUND_GRADIENT_TOP_COLOR, BACKGROUND_GRADIENT_BOTTOM_COLOR });
return gd;
}
但现在我需要一个 SelectorDrawable。
【问题讨论】:
-
好的,谢谢。我想我可以用它做点什么;)