Issue
How to create this shape programmatically?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#e67e22"/>
<corners
android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"/>
</shape>
I've tried this simple function which gets corners, colors and sets that to shape:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.category_header);
GradientDrawable drawable = (GradientDrawable) linearLayout.getDrawable();
float[] values = { 0.2f, 0.2f, 0.2f, 0.2f };
drawable.setCornerRadii(values);
But I got this error:
The method getDrawable() is undefined for the type LinearLayout
Solution
I've created a library which can help to create drawables programmatically.
See here: DrawableToolbox.
With DrawableToolbox, you can create it by:
Drawable drawable = new DrawableBuilder()
.rectangle()
.solidColor(0xffe67e22)
.bottomLeftRadius(20) // in pixels
.bottomRightRadius(20) // in pixels
// .cornerRadii(0, 0, 20, 20) // the same as the two lines above
.build();
Answered By - Hong Duan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.