我正在尝试以编程方式为TextView创建PaintDrawable背景,以便它可以具有圆角底角。这是代码:
View head = findViewById(R.id.ibTitle);
PaintDrawable bkgrnd = new PaintDrawable(R.color.Red);
((PaintDrawable) bkgrnd).setCornerRadii(new float [] {0,0, 0,0, 6,6, 6,6});
head.setBackgroundDrawable((PaintDrawable) bkgrnd);
ibTitle是一个TextView。
问题在于没有任何迹象表明其背景,颜色或角落有任何变化。
我一定很遗憾。请帮忙。
答案 0 :(得分:1)
您也可以在xml中创建圆角,然后仅从资源中设置背景 喜欢来自资源R.drawable.mydrawable
的setbackgroundmygdawable可以是:
<stroke android:width="3dp"
android:color="#ff000000"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
答案 1 :(得分:0)
你在某处做过head.invalidate()吗?