The android.widget.RelativeLayout class provides a way to lay out child views in a relative position to each other. The setBackground() method of RelativeLayout sets the background color or image of the layout.
Example 1: Set background color
RelativeLayout layout = findViewById(R.id.myLayout); //get the layout by id layout.setBackgroundColor(Color.RED); //set the background color to red
Example 2: Set background image
RelativeLayout layout = findViewById(R.id.myLayout); //get the layout by id Drawable background = getResources().getDrawable(R.drawable.background_image); //get the image from the resources layout.setBackground(background); //set the background image
The package library for android.widget.RelativeLayout is android.widget.
Java RelativeLayout.setBackground - 17 examples found. These are the top rated real world Java examples of android.widget.RelativeLayout.setBackground extracted from open source projects. You can rate examples to help us improve the quality of examples.