将位图设置为文本视图的背景 - Android [英] Set Bitmap as background of Text View - Android

查看:28
本文介绍了将位图设置为文本视图的背景 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时在内存中有一个位图.我想将文本视图的背景设置为此位图.我无法为此找到任何标准程序(不是 hacky 程序).如果有人在这方面工作过,请帮忙!

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). If anybody has worked in this area, please help!

推荐答案

根据 API 文档,setBackgroundResource 需要一个整数.

According to the API docs, setBackgroundResource expects an int.

如果您确实需要位图,则可以改用 setBackgroundDrawable 并将位图包装在 BitmapDrawable 中.例子

If you definitely need a bitmap, you can use setBackgroundDrawable instead and wrap your bitmap in a BitmapDrawable. example

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

这篇关于将位图设置为文本视图的背景 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆