You can change the background color of the activity itself as follows:
This is the XML file for the activity:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/backgroundId">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RED"
android:id="@+id/redButton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="70dp"
android:onClick="onRedButtonClick"/>
</RelativeLayout>
This is the java code :
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onRedButtonClick(View view) {
RelativeLayout background = (RelativeLayout) findViewBy(R.id.backgroundId);
background.setBackgroundColor(Color.RED);
}
Hope this helps.