JAW
JAW

Reputation: 227

PaintDrawable background for TextView not visible

I am trying to make programatically a PaintDrawable background for a TextView so it can have rounded bottom corners. Here is the code:

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 is a TextView.

The problem is that there is no indication of any change to its background, color or corners.

I must be missing something simple. Please help.

Upvotes: 0

Views: 1189

Answers (2)

Lukap
Lukap

Reputation: 31963

You can make round corners in xml also and then only set the background from resource like setbackground from resource R.drawable.mydrawable

where mygdawable can be something like:

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

Upvotes: 1

drakon
drakon

Reputation: 165

Did you do head.invalidate() somewhere?

Upvotes: 0

Related Questions