If you are switching in an Activity, you can consider setting the attributes of all visible elements of the current interface according to the switched theme plan; if you are switching in a Fragment, the fragment can also set the theme, like this:
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final Context contextThemeWrapper = new ContextThemeWrapper( getActivity(), isDay ? R.style.day : R.style.night); LayoutInflater localInflater = inflater .cloneInContext(contextThemeWrapper); View v = localInflater.inflate(R.layout.fragment_layout, container, false); return v; }
If you are switching in an Activity, you can consider setting the attributes of all visible elements of the current interface according to the switched theme plan; if you are switching in a Fragment, the fragment can also set the theme, like this:
Bilibili has open sourced a solution on github, you can take a look