The following blog may solve your problem:
http://mrbool.com/how-to-change-the-layout-theme-of-an-android-application/25837
Copy blog code for quick reference:
Assuming you have already identified the following three topics in the XML file R.style.FirstTheme , R.style.SecondTheme and R.style.ThirdTheme
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; public class ChangeThemeActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.onActivityCreateSetTheme(this); setContentView(R.layout.main); findViewById(R.id.button1).setOnClickListener(this); findViewById(R.id.button2).setOnClickListener(this); findViewById(R.id.button3).setOnClickListener(this); } @Override public void onClick(View v) {
Let's write the code below in the "Utils" file:
import android.app.Activity; import android.content.Intent; public class Utils { private static int sTheme; public final static int THEME_DEFAULT = 0; public final static int THEME_WHITE = 1; public final static int THEME_BLUE = 2; public static void changeToTheme(Activity activity, int theme) { sTheme = theme; activity.finish(); activity.startActivity(new Intent(activity, activity.getClass())); } public static void onActivityCreateSetTheme(Activity activity) { switch (sTheme) { default: case THEME_DEFAULT: activity.setTheme(R.style.FirstTheme); break; case THEME_WHITE: activity.setTheme(R.style.SecondTheme); break; case THEME_BLUE: activity.setTheme(R.style.Thirdheme); break; } } }
Hope this helps ...
EDIT 1:
The following reason AlertDialog does not accept a custom theme:
The implementation in Builder.create () is:
public AlertDialog create() { final AlertDialog dialog = new AlertDialog(P.mContext); P.apply(dialog.mAlert); [...] }
which calls the "AlertDialog" constructor, created not by a theme, which looks like this:
protected AlertDialog(Context context) { this(context, com.android.internal.R.style.Theme_Dialog_Alert); }
AlertDialog has a second constructor for changing themes:
protected AlertDialog(Context context, int theme) { super(context, theme); [...] }
that Builder just doesn't call.
Check out the following post for more relevant fixes.
How to change theme for AlertDialog
Below is the most voted answer:
new AlertDialog.Builder( new ContextThemeWrapper(context, android.R.style.Theme_Dialog))