Kapil Rajput
Kapil Rajput

Reputation: 11565

how to change colorPrimary , colorPrimaryDark and colorAccent of an app Programatically

Is it possible to override colorPrimary , colorPrimaryDark and colorAccent values Programatically and change Accordingly from java code at Runtime ? If Possible please help.

Upvotes: 1

Views: 933

Answers (1)

Luca Nicoletti
Luca Nicoletti

Reputation: 2427

No, it's not possible. But you can create multiple Styles and change the Style used by the activity at runtime. To do that use setTheme() before calling setContentView() and super.onCreate() method inside onCreate() method of the activity!

public void onCreate(Bundle savedInstanceState) {

  setTheme(R.style.MyTheme); // (for Custom theme)

  super.onCreate(savedInstanceState);
  this.setContentView(R.layout.myactivity);
}

Upvotes: 2

Related Questions