Я хочу создать приложение android, в котором я могу изменить тему всего приложения во время выполнения, выбрав цвет из списка. Итак, я сделал прослушиватель предмета recyclerview, но есть проблема в том, что предмет выбран, но цвет / тема остаются прежними. Вот мой код.
@Override
public void onClick(View v) {
Constant.color = position;
Methods method = new Methods();
method.setColorTheme();
Log.e("*** Adapter ***", "Selected Color is *** " + position );
colorEditor.putInt("color", Constant.color);
Log.e("Color", "Saved is: " + Constant.color);
colorEditor.putInt("theme", Constant.theme);
Log.e("Theme", "Saved is: " + Constant.theme);
colorEditor.apply();
// chooseColor(position);
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
Toast.makeText(context, "Item Selected is: " + position, Toast.LENGTH_SHORT).show();
}
}); ```
Here's setTheme is a method created in method class in which multiple themes could be selected.
public class Methods {
public void setColorTheme(){
switch (Constant.color){
case 0xffF44336:
Constant.theme = R.style.AppTheme;
break;
case 0xffE91E63:
Constant.theme = R.style.Theme_AppCompat_DayNight_DarkActionBar;
break;
case 0xff9C27B0:
Constant.theme = R.style.themePink;
break;