Issue
I understand how to make Button has rounded corners using GradientDrawable. The question I have now is if I set my background already in xml and retrieve it by
int[] attrsArray = new int[] {
android.R.attr.background
};
TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
Drawable background = ta.getDrawable(0);
ta.recycle();
so I have a Drawable type of background now. next thing I want to do is call setBackgroundDrawable() and pass the drawable background, but I won't be able to set rounded corners with Drawable type. I can't just cast it to GradientDrawable either. Is there a way to achieve this? this way makes things a lot easier because I'll be able to give Button any background and have the rounded corner.
Thanks
Solution
Not sure if your use case is same as mine but I had to once do something similar and I had an invisible Button with a RoundedImageView behind it. The RoundedImageView was below:
https://github.com/vinc3m1/RoundedImageView
Using that class you can set the radius of the image.
Answered By - KVISH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.