I have a shape object defined in XML like below:
<shape android:shape="rectangle">
<gradient
android:startColor="#333"
android:centerColor="#DDD"
android:endColor="#333"/>
<stroke android:width="1dp" android:color="#FF333333" />
</shape>
I want to create an equal object in my code.
I created a GradientDrawable
as below:
gradientDrawable1.setColors(new int[] { 0x333, 0xDDD, 0x333 });
gradientDrawable1.setOrientation(Orientation.TOP_BOTTOM);
But I don't know how to create a Stroke(?) and then assign both Stroke and GradientDrawable
to Shape
Any idea?
Example:
Usage:
Result:
if you want to make it in the code, first inspect what class instance is returned by res.getDrawable(resId) e.g by:
this should surely work, Try
gradientDrawable1.setStroke(1, getResources().getColor(R.color.stroke));
so your code should be :
where color stroke,start,center is defined inside
colors.xml
as: