I want to turn on the night Mode in android Fragment.
The code runs fine in the activity getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
But we cannot use the same code inside the fragment
What is the solution of this?
Is there any alternative way of turning on the nightmode inside the fragment?
The code: ((AppCompatActivity)getActivity()).getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
The above code refreshes the fragment and the fragment as well as the parent activity
((AppCompatActivity)getActivity()).getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);