I assume you duplicate most of the code in the SetThemeX
methods. I would thus recommend introducing a class that captures the essence of a theme and use that:
class MyTheme {
public int background;
public int alpha;
public int color;
public MyTheme(int background, int alpha, int color) {
this.background = background;
this.alpha = alpha;
this.color = color;
}
}
Make one method to set your theme:
public void setTheme(DTypeActivity dTypeActivity, MyTheme theme) {
final EditText edit_text = (EditText) findViewById(R.id.editText1);
final View main_view = (View) findViewById(R.id.mainview);
main_view.setBackgroundDrawable(getResources().getDrawable(theme.background));
edit_text.getBackground().setAlpha(theme.alpha);
edit_text.setTextColor(getResources().getColor(theme.color));
}
And keep a map somewhere in which you store these themes:
Map<Integer, MyTheme> themes = new HashMap<>();
themes.put(1, new MyTheme(R.drawable.grey_background, 0, R.color.DrText));
// put other themes
In your SetApplicableStyle
method you can then simply use
public void SetApplicableStyle (DTypeActivity dTypeActivity, int theme, int font, int size) {
setTheme(dTypeActivity, themes.get(theme);
// set font and size similarly
}