简体   繁体   English

将位图设置为文本视图的背景 - Android

[英]Set Bitmap as background of Text View - Android

I have a bitmap in memory at run-time. 我在运行时在内存中有一个位图。 I want to set the background of a text view to this bitmap. 我想将文本视图的背景设置为此位图。 I am not able to find any standard procedure for that (not a hacky one). 我无法找到任何标准程序(不是一个hacky程序)。 If anybody has worked in this area, please help! 如果有人在这方面工作过,请帮忙!

According to the API docs, setBackgroundResource expects an int. 根据API文档,setBackgroundResource需要一个int。

If you definitely need a bitmap, you can use setBackgroundDrawable instead and wrap your bitmap in a BitmapDrawable. 如果你肯定需要一个位图,你可以改用setBackgroundDrawable并将你的位图包装在BitmapDrawable中。 example

textureView.setBackground(new BitmapDrawable(getResources(), bitmap));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM