I am looking for a way to enable night mode programmatically with an Android code:
public static void setNightMode(Context target , boolean state){
UiM
NightOwl has its own implementation for switching day/night mode on Android. Getting started with NightOwl is super easy. Here's a code snippet:
Init the NightOwl in Application class,
NightOwl.builder().defaultMode(0).create();
Call three method in your Activity class,
public class DemoActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// step1 before super.onCreate
NightOwl.owlBeforeCreate(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
// step2 after setContentView
NightOwl.owlAfterCreate(this);
// write your code
}
@Override
protected void onResume() {
super.onResume();
// step3 onResume
NightOwl.owlResume(this);
}
}
Switch skin everywhere as you like,
View v = findViewById(R.id.button);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NightOwl.owlNewDress(SettingActivity.this);
}
});