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 test1 = 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.