When you install the custom theme setTheme() for some reason, only ColorPrimaryDark color ColorPrimaryDark . Here is the topic itself

 <style name="Red" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:colorPrimary">#ca3030</item> <item name="android:colorPrimaryDark" >#a42525</item> </style> 

I change the theme from my own ThemeUtils class ThemeUtils Here is the class itself.

 package alphacorp.com.touristapp; import android.app.Activity; import android.content.Intent; public class ThemeUtils{ private static int sTheme; public final static int FIRE_BRICK = 0; public final static int DODGER_BLUE = 1; public static void changeToTheme(Activity activity, int theme) { sTheme = theme; activity.finish(); activity.startActivity(new Intent(activity, activity.getClass())); activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } public static void onActivityCreateSetTheme(Activity activity) { switch (sTheme) { default: activity.setTheme(R.style.AppTheme); break; case R.id.red: activity.setTheme(R.style.Red); break; case R.id.vk: activity.setTheme(R.style.Vk); break; case R.id.green: activity.setTheme(R.style.Green1); ;break; case R.id.pink1: activity.setTheme(R.style.Pink); ;break; case R.id.orange: activity.setTheme(R.style.Orange); ;break; case R.id.black: activity.setTheme(R.style.Black); case R.id.green2: activity.setTheme(R.style.Green2); case R.id.blue: activity.setTheme(R.style.Blue2); case R.id.pink2: activity.setTheme(R.style.Pink2); } } } 
  • android:colorPrimary requires an API version of 21 or higher. On which version of Android do you watch? - Vadik
  • I am using version 7 - ILHOM4IK
  • ThemeOverlay theme is usually used for toolbars, if you have a theme for activating or for an application, you need to specify the parent Theme.AppCompat or Theme.AppCompat.Light - Vadik
  • your varieant doesn't work - ILHOM4IK
  • Complete the question, if you custom call setTheme from the code, where do you do it? (give an example code) - Vadik

1 answer 1

Try android: without prefix, and also if this theme is set to activate, then you should specify Theme.AppCompat as the parent theme (or Theme.AppCompat.Light for the light theme):

 <style name="Red" parent="Theme.AppCompat"> <item name="colorPrimary">#ca3030</item> <item name="colorPrimaryDark">#a42525</item> </style> 

Also keep in mind that if you set setTheme () dynamically from the code, then it is better to do this before calling super.onCreate () in activation.

And also: it is possible that your toolbar has its own styles, which is why you don’t see any changes.

  • does not work, this time the color of the statusbar also has not changed - ILHOM4IK