0

Hello I'm a newbie in android development and I am looking forward a way to change the background color.

Here is my code:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// View layout = new View(this);
// layout.setBackgroundColor(android.R.color.holo_blue_light);
// View root = layout.getRootView();
// root.setBackgroundColor(android.R.color.holo_green_dark);
View view = this.getWindow().getDecorView();
view.setBackgroundColor(R.color.red); 
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
user2277536
  • 55
  • 1
  • 3

3 Answers3

2

The problem is with the syntax view.setBackgroundColor(R.color.red);
Try:

view.setBackgroundColor(Color.RED); 
Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
1

view.setBackgroundResource(R.drawable.example);

rahultheOne
  • 154
  • 1
  • 8
0

used this :-

 view.setBackgroundColor(ContextCompat.getColor(context, R.color.color_name))

This will choose the Marshmallow two parameter method or the pre-Marshmallow method appropriately.

Ashwani kumar
  • 164
  • 15