Issue
I need to modify an xml drawable corner radius programmatically from Java.
XML looks like this (can be modified):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomRightRadius="32dp"
android:bottomLeftRadius="32dp"
android:topRightRadius="32dp"
android:topLeftRadius="32dp"/>
</shape>
I have gotten this far.
Resources res = context.getResources();
Drawable customRoundedButton = ResourcesCompat.getDrawable(res, R.drawable.custom_rounded_button, null);
// customRoundedButton somehow modify corners??
// customRoundedButton.setCornerRadii(16); // What I would like to do in pseudo code
PiaInterfaceConfiguration.getInstance().setButtonRoundCorner(R.drawable.custom_rounded_button);
Problem is PiaInterfaceConfiguration only accepts drawable reference in the form of int.
Solution
if your PiaInterfaceConfiguration
takes only resource id int
then you can't change these corners, you have to create another, not changeable XML or modify this class (add int roundCorner
param and set it inside this class like you have tried with commented code)
edit: for setting corner radius you have to use setCornerRadius(float)
method, which belongs to GradientDrawable
. so your Drawable customRoundedButton
must be casted to GradientDrawable
(even when there is solid color, gradient "feature" not used)
Drawable customRoundedButton = ...
if (customRoundedButton instanceof GradientDrawable) { // check just for safety
((GradientDrawable) customRoundedButton).setCornerRadius(22f); // float
}
Answered By - snachmsm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.