设置背景图像不是从drawable文件夹

时间:2013-10-22 09:09:15

标签: android android-drawable

我想设置一个背景图片但不是来自drawable文件夹,图片来自图库,它是内部存储。

有可能吗?

2 个答案:

答案 0 :(得分:1)

从活动

中调用此方法
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

您可以从Activity打开Gallery intent并处理OnActicityResult方法..... Try This link for solution

所以,现在对于setBacground,您可以使用下面的代码将位图转换为drawable ..

Drawable d = new BitmapDrawable(getResources(),bitmap);
view.setBackground(d);

我希望这可以帮助你...

答案 1 :(得分:0)

将图像作为位图从图库中获取,并在imageview中显示该位图 这是一个非常好的tutorial在ImageView中显示图库的图像。

相关问题