2023-08-17 10:46:24 +02:00
|
|
|
package android.view;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.ContextWrapper;
|
2023-11-08 21:29:46 +01:00
|
|
|
import android.content.res.Resources;
|
2023-08-17 10:46:24 +02:00
|
|
|
|
|
|
|
|
public class ContextThemeWrapper extends ContextWrapper {
|
|
|
|
|
|
2024-06-15 22:32:01 +02:00
|
|
|
private Resources.Theme theme = null;
|
|
|
|
|
|
|
|
|
|
public ContextThemeWrapper(Context base) {
|
|
|
|
|
super(base);
|
|
|
|
|
}
|
2023-11-08 21:29:46 +01:00
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
public ContextThemeWrapper(Context context, int themeResId) {
|
|
|
|
|
super(context);
|
2023-11-08 21:29:46 +01:00
|
|
|
setTheme(themeResId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setTheme(int resid) {
|
2024-06-15 22:32:01 +02:00
|
|
|
if (theme == null) {
|
|
|
|
|
theme = getResources().newTheme();
|
|
|
|
|
theme.setTo(getBaseContext().getTheme());
|
|
|
|
|
}
|
2023-11-08 21:29:46 +01:00
|
|
|
theme.applyStyle(resid, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Resources.Theme getTheme() {
|
2024-06-15 22:32:01 +02:00
|
|
|
if (theme != null)
|
|
|
|
|
return theme;
|
|
|
|
|
else
|
|
|
|
|
return super.getTheme();
|
2023-08-17 10:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|