Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getDelegate() method inside a fragment?

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?

Error in 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

like image 378
Paul's omg Hardware Avatar asked Oct 29 '25 15:10

Paul's omg Hardware


1 Answers

((AppCompatActivity)getActivity()).getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);

like image 116
Alex Timonin Avatar answered Nov 01 '25 04:11

Alex Timonin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!