欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android安卓设置assets里的文件夹作为背景

程序员文章站 2022-03-15 13:30:06
本文档为个人博客文档系统的备份版本、作者:小游、作者博客:点击访问直接使用下面的代码来实现就可以了。try {InputStream is=getAssets().open("imgs/bg.png");Bitmap bm= BitmapFactory.decodeStream(is);is.close();Drawable da=new BitmapDrawable(getResources(),bm);appBackground.setBackground(da);} ca....

本文档为个人博客文档系统的备份版本、作者:小游、作者博客:点击访问

直接使用下面的代码来实现就可以了。

try {
	InputStream is=getAssets().open("imgs/bg.png");
	Bitmap bm= BitmapFactory.decodeStream(is);
	is.close();
	Drawable da=new BitmapDrawable(getResources(),bm);
	appBackground.setBackground(da);
} catch (IOException e) {
	e.printStackTrace();
}

因为图片不是drawable格式的,所以我们需要先以字节流的方式读出文件,然后转换为bitmap
最后再转换为drawable就可以了。

本文地址:https://blog.csdn.net/xiaoyou625/article/details/110674107

相关标签: 程序语言