How to change AppTheme?

1

I have 2 styles files. With a click on a button I want to switch from AppTheme to AppTheme2. how to do?

   Manifest.xml
   <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">

      styles.xml
      <resources>
      <style name="AppTheme" parent="Theme.AppCompat">
    <item name="android:windowBackground">@drawable/background</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
   </style>
  </resources>


     styles2.xml
    <resources>
  <style name="AppTheme2" parent="Theme.AppCompat">
  <item name="android:windowBackground">@drawable/background</item>
  <item name="colorPrimary">@color/colorPrimary2</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
  </style>
  </resources>
    
asked by anonymous 28.07.2018 / 03:27

1 answer

-1

You can only change it from position Before

Before:

<color name="colorPrimary2">#000000</color>
<color name="colorPrimary">#32515f</color>

Then:

<color name="colorPrimary2">#32515f</color>
<color name="colorPrimary">#000000</color>

You can add another color in the resource.

    
28.07.2018 / 03:35