How do I change the theme of my app in android studio?

4.7k views Asked by At

I change the theme from the design section from the dropdown menu like material dark, holo, etc. But when I run the app on the device the app doesn't show any changes, hence I understood the code does not change so what is the code I need to write in style section to change the theme?

4

There are 4 answers

0
hosein moradi On
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_second);
   if(mode.equals("dark")){
     setTheme(android.R.style.DarkTheme);
   }else if(mode.equals("light")){
     setTheme(android.R.style.LightTheme);
   }else{
     setTheme(android.R.style.AppTheme);
   }
 }
0
Maxim Firsoff On

AndroidStudio only shows how it will look if you will apply that theme in your app programmatically by yourself.

0
Sharad Kale On

In res/values/styles.xml you can add following code to change theme:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
        <item name="windowNoTitle">true</item>
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
        <item name="android:statusBarColor">@color/colorPrimaryDark</item>
        <item name="android:colorControlActivated">@color/colorPrimaryDark</item>
        <item name="android:colorControlHighlight">@color/colorPrimary</item>
        <item name="android:colorControlNormal">@color/colorPrimary</item>
        <item name="android:windowBackground">@color/colorBackground</item>
        
    </style>
</resources>

you can change theme by modifying parent attribute

0
Gregor Rant On

You should edit the application manifest and add android:theme attribute to either application or activity tag with the theme you want.