How to disable night mode in my application even if night mode is enable in android 9.0 (pie)?

前端 未结 8 934
悲&欢浪女
悲&欢浪女 2020-12-16 12:32

I created my application before the android pie has been released, in every layout I put android: background = \"white\" it works fine in every device, but when

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 13:10

    What suggested by Ali Rezaiyan is the correct way to proceed if you want disable the night mode all over your app.

    Sometimes you just need to disable the night mode on some activities or fragment only (maybe because of legacy stuff).

    So you can choose what to do:

    • Disable all over the app:

      • AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
    • Disable for a single Activity:

      • getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
      • After calling this you probably need to call recreate() for this to take effect

提交回复
热议问题