0

There are 3 different types of style in the styles.xml like the following:

<style name="Theme_A" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#01AC50</item>
    <item name="colorPrimaryDark>#FF007838</item>
    <item name="colorAccent">#009688</item>"
<style>

The users are able to choose which style they want using the buttons, how can I change the whole Activity's style after clicking on the button?

GianhTran
  • 3,443
  • 2
  • 22
  • 42

2 Answers2

0

Try this:-

You need to use setTheme() Function before the setContentView()

as doc say's you need to define Theme before the view instantiate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     setTheme(android.R.style.Theme_Dark);
     .
     .
     setContentView(R.layout.main);
}
Mr. Roshan
  • 1,777
  • 13
  • 33
0

How to setTheme to an activity at runtime? It doesn't work call setTheme before onCreate and setContentView has the suggestion to use

setContentView(...);
setTheme(R.style.MyTheme);
setContentView(...);

That is: it seems you need to setContentView after setTheme, as

[setTheme] should be called before any views are instantiated in the Context

serv-inc
  • 35,772
  • 9
  • 166
  • 188