开发者

Set Background - Picture in Framelayout

Perhaps very simple, but not for me ;)

How do i change the Picture of a Framelayout in my sourcecode?

My first intention was:

mBackgroundDrawable = getRes开发者_Python百科ources().getDrawable(R.drawable.picture);
main.setBackgroundDrawable(mBackgroundDrawable);

but there i only can add pictures from my "RES/DRAWABLE-HDPI" folder. I want to use my SD-Card as the destinated source.

Whats the right way?


Try this:

Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png");
image.setImageBitmap(bMap);
BitmapDrawable dr=new BitmapDrawable(bMap);


You'll need to convert your Bitmap to a BitmapDrawable before able to set it as a background.

val bitmap = BitmapFactory.decodeFile(this.file.absolutePath)
frameLayout.background = BitmapDrawable(context.resources, bitmap)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜