2011-10-28 49 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