如何从资源文件夹中的android设置背景图片? [英] How to Set Background Image from asset folder in android?

查看:577
本文介绍了如何从资源文件夹中的android设置背景图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的问题,同时设置的LinearLayout的背景图像的资源文件夹。

I am facing problem while setting the backGround Image of LinearLayout from asset folder.

String filePath="file:///android_asset/images/test.png";
    Drawable d = Drawable.createFromPath(filePath);
    frontTextView.setBackgroundDrawable(d);

有人可以帮助我。

Can someone help me out.

推荐答案

好了,万一别人绊倒在这里,有您想从图像这是在资产设置视图的背景这一非常问题:

Ok, in case anyone else stumbles here, with this very problem where you want to set a view's background from an image which is in assets:

Drawable d = Drawable.createFromStream(getAssets().open(path_in_assets), null);

然后将其设置在一定认为,只有支持可绘制作为背景。

and then set it to some View that only supports Drawables as a background.

这篇关于如何从资源文件夹中的android设置背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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