RelativeLayout layout = findViewById(R.id.my_layout); layout.setBackgroundResource(R.drawable.my_image);
RelativeLayout layout = findViewById(R.id.my_layout); layout.setBackgroundResource(android.R.color.white);In this example, we set the background of the RelativeLayout to a system color defined in the android.R.color class. We pass the resource ID of the color "white" to setBackgroundResource(). Package/Library: android.widget.RelativeLayout is part of the Android SDK, specifically the android.widget package.