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

设置TextView的drawable:

			Drawable drawableleft = getResources().getDrawable(
					R.drawable.icon_qq_gray);
			drawableleft.setBounds(0, 0, drawableleft.getMinimumWidth(),
					drawableleft.getMinimumHeight());

			txt_bind_qq.setCompoundDrawables(drawableleft, null,
					TextToDrawable(R.string.bound), null);

把字符串转化为drawable:

	public Drawable TextToDrawable(int id) {
		Bitmap bitmap = Bitmap.createBitmap(200, 250, Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		Paint paint = new Paint();
		paint.setTextSize(65);
		paint.setTextAlign(Align.LEFT);
		paint.setColor(Color.GRAY);
		String s = getResources().getString(id);
		FontMetrics fm = paint.getFontMetrics();
		canvas.drawText(s, 0, 145 + fm.top - fm.ascent, paint);
		canvas.save();
		Drawable drawableright = new BitmapDrawable(bitmap);
		drawableright.setBounds(0, 0, drawableright.getMinimumWidth(),
				drawableright.getMinimumHeight());
		return drawableright;
	}




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