// Find the View by ID View myView = findViewById(R.id.my_view); // Set the background resource to an image myView.setBackgroundResource(R.drawable.background_image);
// Create a new ImageView ImageView imageView = new ImageView(this); // Set the background resource to a drawable with a shape imageView.setBackgroundResource(R.drawable.rounded_corners); // Add the ImageView to a parent ViewGroup ViewGroup parent = findViewById(R.id.parent_view); parent.addView(imageView);This example creates a new ImageView programmatically, sets its background to a drawable with rounded corners, and adds it to a parent ViewGroup. The package library for this is likely android.view or android.widget.