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?
How do I change the theme of my app in android studio?
4.8k Views Asked by Shrey Makwana At
4
There are 4 best solutions below
0
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
On
You should edit the application manifest and add
android:theme attribute to either application or activity tag with the theme you want.
0
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);
}
}
AndroidStudio only shows how it will look if you will apply that theme in your app programmatically by yourself.