views:

45

answers:

3

Actually, what I want is a textview which can show the progress of something, I know progressbar in android,however,so far as I know, it can not contain any text(am I right?), so, I want to change the background color of the textview to show progress,from left to right gradually.

Is there any other way to do this ?

Thanks in advance?

A: 

I've done something similar, but for the background of a list item.

The trick to is draw the background on a Bitmap, wrap that in a BitmapDrawable, and pass the latter to the TextView using setBackgroundDrawable:

Bitmap b = getProgressBackground();
BitmapDrawable bd = new BitmapDrawable(b);
textView.setBackgroundDrawable(bd);

GetProgressBackground is a custom function. The gist of it is:

Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas();
c.setBitmap(b);

//Draw stuff on the Canvas

return b;
benvd
+1  A: 

Use textview.setBackgroundResource(R.color.yourcolor);

success_anil
A: 

Why not try it the other way? Use a RelativeLayout, ProgressBar and place a TextView on top of the ProgressBar. Change the layout/progress bar properties so the TextView is placed on the inside center of the progress bar. You could change the bar's progress and at the same time shows progress text easily this way.

anmustangs