1 GradientDrawable shape = new GradientDrawable();
2 shape.setCornerRadius( 8 );
3
4 // add some color
5 // You can add your random color generator here
6 // and set color
7 if (i % 2 == 0) {
8 shape.setColor(Color.RED);
9 } else {
10 shape.setColor(Color.BLUE);
11 }
12
13 // now find your view and add background to it
14 View view = (LinearLayout) findViewById( R.id.my_view );
15 view.setBackground(shape);