开发者

How to change the background color of a TextView in android?

Actually, what I want is a textview which can show the progress of something, I know progressbar in an开发者_Go百科droid,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?


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


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜