0

This is my actuall style.xml of my app:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:alertDialogTheme">@style/customDialog</item>
    <item name="android:actionBarStyle">@style/customActionBar</item>
</style>


<style name="LoginStyle" parent="AppTheme.Base">
    <item name="colorPrimaryDark">@color/Material_Blue</item>
    <item name="colorControlNormal">#c5c5c5</item>
    <item name="colorControlActivated">#FFFFFF</item>
    <item name="colorControlHighlight">#FFFFFF</item>
</style>

<style name="MainStyle" parent="AppTheme.Base">
    <item name="android:actionBarTheme">@style/customActionBar</item>
    <item name="android:colorAccent">@color/md_material_blue_600</item>
    <item name="colorPrimaryDark">@color/Material_Blue</item>
    <item name="colorControlNormal">@color/md_material_blue_600</item>
    <item name="colorControlActivated">@color/md_material_blue_600</item>
    <item name="colorControlHighlight">@color/md_material_blue_600</item>
</style>

<style name="customDialog">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
    <item name="colorControlActivated">@color/md_material_blue_600</item>
    <item name="android:colorControlHighlight">@color/md_material_blue_600</item>
    <item name="android:button">@color/md_material_blue_600</item>
</style>

<style name="customActionBar">
    <item name="android:background">@color/Material_Blue</item>
</style>

As you can see, my app has some different themes, but now some users asked me to implement a feature that can switch the "light theme" to the "dark theme". Now, if I change the theme parent of the AppTheme.Base to Theme.AppCompat, the entire application gets the "dark theme".

So, is there a way to change the parent theme of the base theme? Or what I need to do in order to get my result?

I've read this: https://stackoverflow.com/a/18301723/5327202, I've implemented those classes but it only change the text color to white and nothing else.(Of course I've created another style in the xml; essentially, I've copy-pasted the original theme and then changed the AppTheme.Base parent to Theme.AppCompat)

Thanks.

Community
  • 1
  • 1
CallMeDeftsu4
  • 129
  • 1
  • 12

1 Answers1

1

Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling setContentView(View) or inflate(int, ViewGroup)).

check http://developer.android.com/reference/android/content/Context.html#setTheme%28int%29

public void onCreate(Bundle savedInstanceState) {
    setTheme(android.R.style.Theme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
}
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Krunal Patel
  • 129
  • 3
  • 12