1

是否可以从 textview 和 imageview 创建图像并将 appicon 设置为图像?

像这样的东西:

TextView tv = new TextView(getBaseContext());
    tv.setText("Hello");

    tv.buildDrawingCache();
    ImageView img = new ImageView(getBaseContext());
    img.setImageBitmap(tv.getDrawingCache());

    img.buildDrawingCache();
    Bitmap bmap = img.getDrawingCache();

    Drawable d = new BitmapDrawable(getResources(), bmap);

    getActionBar().setIcon(d);
4

1 回答 1

1

你为什么不使用 Canvas ? 将字符串文本转换为位图

您可以绘制文本和位图,然后设置操作栏的图标。您可以通过以下方式获取 ImageView 的位图:

Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();

然后在画布中绘制文本和位图并从中生成位图。可以使用绘图缓存,但不建议使用。

至于您的问题,您应该先尝试您的方法,然后再询问它是否可以在这里工作。

于 2013-08-09T10:33:52.963 回答