I would like to set a background image but not from drawable folder, the image is from gallery which is internal storage.
Is it possible to do that ?
I would like to set a background image but not from drawable folder, the image is from gallery which is internal storage.
Is it possible to do that ?
从 Activity 调用它
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
您可以从 Activity 打开 Gallery 意图并处理 OnActicityResult 方法.....尝试此链接以获取解决方案
所以,现在对于 setBacground,您可以使用下面的代码将位图转换为可绘制的..
Drawable d = new BitmapDrawable(getResources(),bitmap);
view.setBackground(d);
我希望这可以帮助你...
从图库中获取图像作为位图并在 imageview 中显示该位图 这是一个非常好的教程,用于在 ImageView 中显示图库中的图像。