设置在SD卡中找到的背景图像

时间:2012-01-26 17:37:03

标签: android

在我的应用程序中,我希望能够允许用户将图像放入我的应用程序创建的文件夹中,然后将其放入堆栈中,将其设置为图像背景。

  

问题是如何在代码上设置背景图像?

我知道您可以将图像放在drawable中并将其设置为xml但我希望用户能够随意从他们喜欢的背景中进行选择。

感谢。

这就是我尝试过的。如果可能的话,请纠正我,因为它不起作用。

Bitmap backgroundBitmap = BitmapFactory.decodeFile(backgroundFileLocation);
Drawable backgroundImage = new BitmapDrawable(backgroundBitmap);
LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout_layout_options);
ll.setBackgroundDrawable(backgroundImage);

1 个答案:

答案 0 :(得分:1)

通过使用bitmapfactory.decodefile()加载图像然后使用bitmapDrawable

,从SD卡中获取drawable后,使用线性布局和setBackgroundDrawable()