Фриланс
6
Вклад в тег
private void addRoundedBackground(final TextView textView, final int color, final int borderColor) {
textView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
final float height = textView.getHeight();
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(height/2);
shape.setColor(color);
shape.setStroke(1, borderColor);
textView.setBackgroundDrawable(shape);
}
});
}