gpt4 book ai didi

java - 创建位图并将其设置为操作栏图标。可能的?

转载 作者:行者123 更新时间:2023-12-01 14:15:27 25 4
gpt4 key购买 nike

是否可以从 TextView 和 ImageView 创建图像并将应用图标设置为图像?

类似这样的事情:

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);

最佳答案

为什么不使用 Canvas ? Convert String text to Bitmap

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

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

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

至于你的问题,你应该先尝试一下你的方法,然后再询问它是否在这里有效。

关于java - 创建位图并将其设置为操作栏图标。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18144357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com