I am creating a simple examination result storage program. The activity changes theme depending on the user's current result - for example blood red for a failing grade e.t.c. When a user deletes a subject and it causes a significant change in the overall result, the theme changes. The theme is decided by this method:
private int getTheme()
{
String[] themes={"GreenTheme","TurquoiseTheme","OrangeTheme","RedTheme","BlackTheme"};
int index=0;
float gpa =getSemesterGpa(currentSemester);
if (gpa >= 3.5)
index = 0;
else if (gpa >= 3)
index = 1;
else if (gpa >= 2.5)
index = 2;
else if (gpa >= 2)
index=3;
else
index=4;
return getResources().getIdentifier(themes[index],"style",getPackageName());
}
And I have in my onCreate():
protected void onCreate(Bundle savedInstanceState)
{
setTheme(getSgpaTheme());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_semester_detail);
...
}
Whenever a subject deletion causes a major change in the GPA, I use recreate() so that the activity is reloaded with the new theme. As I understand it, there is no other way to apply the new theme dynamically. Unfortunately, recreate() tends to produce a jarring flicker of the screen. On one device, a Samsung S9+, the screen even goes black for a moment. But on my S7 and Huawei device there is only a flicker, still very annoying.
So the question is: is there a way to achieve this, with or without recreate(), which would allow me add a nice fade-in transition as the colors change.
P.S: This is my first question so please excuse if I have provided too little information. I wasn't sure what was relevant. Also, I have only been programming in Java and Android-Studio for about 3 weeks, so I request a noob-oriented answer. Thank you.