Reputation: 4383
I'm trying to set a relative layout's background with,
relativeLayout1.setBackgroundColor(0x00000000);
My program keeps crashing though. Here's the logcat.
Code:
RelativeLayout window=(RelativeLayout) findViewById(R.id.window);
window.setBackgroundColor(0x00000000);
That's the only stuff apart from the regular code setContentView(R.layout.something);
and super.onCreate(savedInstanceState);
Entire code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_invisible);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
window=(RelativeLayout) findViewById(R.id.window);
window.setBackgroundColor(0x00000000);
}
Upvotes: 0
Views: 1059
Reputation: 4383
This was another of Eclipse's moments. It didn't compile my code, so I was executing the old code. Restarted Eclipse and my app works fine now.
Upvotes: 0
Reputation: 1202
You can use this instead relative layout.setBackgroundDrawable(get resources().get drawable(R.drawable.bg);
Or you could define it in XML android: background="@drawable/bg"
Upvotes: 0
Reputation: 20934
From the logcat attached, I can say that most likely your window
pointer is null
at the time you are trying to set background color. It can be caused by different types of problems:
something.xml
layout does NOT contain element with android:id="@+id/window"
attributesomething.xml
layout DOES contain element with android:id="@+id/window"
attribute, but this element is not RelativeLayout
Upvotes: 1
Reputation: 776
Is there is your R.layout.something
a layout with the id R.id.window
?
Maybe you've missed something?
Upvotes: 0