我有一个在XML中定义的形状对象,如下所示:
<shape android:shape="rectangle">
<gradient
android:startColor="#333"
android:centerColor="#DDD"
android:endColor="#333"/>
<stroke android:width="1dp" android:color="#FF333333" />
</shape>
我想在我的代码中创建一个相等的对象。
我已经创建了一个如下的 GradientDrawable
:
gradientDrawable1.setColors(new int[] { 0x333, 0xDDD, 0x333 });
gradientDrawable1.setOrientation(Orientation.TOP_BOTTOM);
但是我不知道如何创建一个Stroke(?),然后将Stroke和GradientDrawable
都分配给Shape
有什么想法吗?