The above answers are nice.You can also go like this programmatically if you want
First, your layout should have an ID. Add it by writing following +id
line in res/layout/*.xml
<RelativeLayout ...
...
android:id="@+id/your_layout_id"
...
</RelativeLayout>
Then, in your Java code, make following changes.
RelativeLayout rl = (RelativeLayout)findViewById(R.id.your_layout_id);
rl.setBackgroundColor(Color.RED);
apart from this, if you have the color defined in colors.xml, then also you can do programmatically :
rl.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.red));