【发布时间】:2018-11-22 18:14:00
【问题描述】:
我有简单的TextView。我想用圆角设置简单的彩色背景。
我尝试了两种方法。
public static Drawable createRoundDrawable(int color, float radius) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setColor(color);
drawable.setCornerRadius(radius);
return drawable;
}
和
public static Drawable createRoundDrawable(int color, float radius) {
PaintDrawable drawable = new PaintDrawable(color);
drawable.setCornerRadius(radius);
return drawable;
}
我使用createRoundDrawable 方法创建drawable 并将背景设置为textView by
textView.setBackground(background);
因此,背景应用于 textView,但角没有任何半径。为什么?以及如何解决?
【问题讨论】:
-
我在示例项目中尝试了您的代码。这个对我有用。您能否向我们分享其他信息,例如您的 xml 文件、使用的 api 等。
标签: android