How to enable night mode programmatically?

后端 未结 3 467
别跟我提以往
别跟我提以往 2020-12-15 06:44

I am looking for a way to enable night mode programmatically with an Android code:

public static void setNightMode(Context target , boolean state){

    UiM         


        
3条回答
  •  星月不相逢
    2020-12-15 07:22

    Make sure to change the default theme from Theme.AppCompat.Light.DarkActionBar to Theme.AppCompat.DayNight.DarkActionBar in the styles.xml file and then do AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) to switch to the night mode. I have tested it in APIv23(Android 6.0) and above and it is working fine. For a better explanation see this codelab by Android

提交回复
热议问题