Created
January 24, 2017 05:28
-
-
Save baleen37/ec3a4505819df1bfd327e86f06a125ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RoundedTextView extends TextView { | |
private float mRadius = 0f; | |
public RoundedTextView(Context context) { | |
super(context); | |
init(context, null); | |
} | |
public RoundedTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(context, attrs); | |
} | |
public RoundedTextView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
init(context, attrs); | |
} | |
private void init(Context context, AttributeSet attrs) { | |
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedTextView); | |
mRadius = a.getDimension(R.styleable.RoundedTextView_rtvRadius, 0f); | |
a.recycle(); | |
GradientDrawable gd = new GradientDrawable(); | |
gd.setCornerRadius(mRadius); | |
int color = Color.TRANSPARENT; | |
Drawable background = getBackground(); | |
if (background instanceof ColorDrawable) | |
color = ((ColorDrawable) background).getColor(); | |
gd.setColor(color); | |
setBackground(gd); | |
} | |
public float getRadius() { | |
return this.mRadius; | |
} | |
public void setRadius(int radius) { | |
this.mRadius = radius; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment