把String字符串转化为drawable设置成TextView的drawableRight

设置TextView的drawable:

[java]  view plain  copy
 
  1. Drawable drawableleft = getResources().getDrawable(  
  2.         R.drawable.icon_qq_gray);  
  3. drawableleft.setBounds(00, drawableleft.getMinimumWidth(),  
  4.         drawableleft.getMinimumHeight());  
  5.   
  6. txt_bind_qq.setCompoundDrawables(drawableleft, null,  
  7.         TextToDrawable(R.string.bound), null);  

把字符串转化为drawable:

[java]  view plain  copy
 
  1. public Drawable TextToDrawable(int id) {  
  2.     Bitmap bitmap = Bitmap.createBitmap(200250, Config.ARGB_8888);  
  3.     Canvas canvas = new Canvas(bitmap);  
  4.     Paint paint = new Paint();  
  5.     paint.setTextSize(65);  
  6.     paint.setTextAlign(Align.LEFT);  
  7.     paint.setColor(Color.GRAY);  
  8.     String s = getResources().getString(id);  
  9.     FontMetrics fm = paint.getFontMetrics();  
  10.     canvas.drawText(s, 0145 + fm.top - fm.ascent, paint);  
  11.     canvas.save();  
  12.     Drawable drawableright = new BitmapDrawable(bitmap);  
  13.     drawableright.setBounds(00, drawableright.getMinimumWidth(),  
  14.             drawableright.getMinimumHeight());  
  15.     return drawableright;  
  16. }  

你可能感兴趣的:(把String字符串转化为drawable设置成TextView的drawableRight)