How to change Apptheme?

Asked

Viewed 279 times

1

I have 2 Styles files. With a click on a button I want to change 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>

1 answer

-1

You can just change him from position Before

Before:

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

Afterward:

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

You can add another color in Resource.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.