开发者

Android - How to change grey background created by a BitmapDrawable

I'm using the follow code, to create a non-scaled, centred image as a background, in a relative layout:-

RelativeLayout explosionlayout = (RelativeLayout) findViewById (R.id.explosionlayout);
explosionlayout.setBackgroundColor(R.color.white);

Bitmap myBitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bomb);
    BitmapDrawable t开发者_运维百科est1 = new BitmapDrawable(myBitmap);
    test1.setGravity(Gravity.CENTER);

The only problem I have, is that the background of the relativelayout is grey, regardless of what I set it to, either via XML or in code.

Any ideas would be appreciated, thanks.


You probably want this instead:

explosionlayout.setBackgroundColor(getResources().getColor(R.color.white));

or just

explosionlayout.setBackgroundColor(0xffffffff);

The reason is that R.color.white is an ID, while setBackgroundColor expects an actual 32-bit integer representation of the color.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜