2011-10-28 51 views
0

我想为编辑器制作一个TextView的PaintDrawable背景,以便它可以有圆角的底角。这里是代码:用于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。

问题是没有迹象表明其背景,颜色或角落有任何变化。

我必须缺少一些简单的东西。请帮忙。

回答

1

你可以在XML还圆角,然后只能从资源 设置背景就像从资源的setBackground R.drawable.mydrawable

其中mygdawable可以是这样的:

<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"/> 

+0

是的,谢谢。但我想要使用PaintDrawable,我可以重新编程。 – JAW

+0

Lukap,我回来了,并试用了你的方法,并决定这是完成我所需要的最简单的方法。我发现我可以通过head.setBackgroundResource(R.drawable.bkgrnd)设置背景; – JAW

+0

或通过在定义TextView的布局xml中设置android:background =“@ drawable.bkgrnd。对于我使用的bkgrnd.xml: \t < \t \t机器人:bottomRightRadius = “8DP” \t \t机器人:bottomLeftRadius = “8DP” \t \t机器人:topLeftRadius = “0dp” \t \t机器人:topRightRadius = “0dp” \t \t /> JAW

0

你是否在某处做过head.invalidate()?

+0

谢谢你的想法,但我试过在第e bkgrnd是在setBackgroundDrawable之后声明的。没有改变,没有表明代码被执行。 – JAW