NightModel Android夜间模式切换库 项目简介
NightModel是一个方便切换夜间模式的库,利用官方夜间模式,同时不用重启Activity。使用要求:官方包support appcompat 23.2.0 或以上版本activity 需要继承自 AppCompatActivity应用按照官方的夜间模式实现使用:1.在appication中初始化public class AppApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
NightModelManager.getInstance().init(this);
...
}
}2.只需要在需要刷新的activity中调用attach、detach方法。其它activity不需要调用此方法public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// must before super.onCreate
NightModelManager.getInstance().attach(this);
super.onCreate(savedInstanceState);
}
...
@Override
protected void onDestroy() {
NightModelManager.getInstance().detach(this);
super.onDestroy();
}
}3.切换时调用appleyDayModel\appleyNightModel进行夜间模式切换private void changeNightModel() {
if (NightModelManager.getInstance().isCurrentNightModel(this)) {
NightModelManager.getInstance().applyDayModel(this);
} else {
NightModelManager.getInstance().applyNightModel(this);
}
}
@Override
public void onCreate() {
super.onCreate();
NightModelManager.getInstance().init(this);
...
}
}2.只需要在需要刷新的activity中调用attach、detach方法。其它activity不需要调用此方法public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// must before super.onCreate
NightModelManager.getInstance().attach(this);
super.onCreate(savedInstanceState);
}
...
@Override
protected void onDestroy() {
NightModelManager.getInstance().detach(this);
super.onDestroy();
}
}3.切换时调用appleyDayModel\appleyNightModel进行夜间模式切换private void changeNightModel() {
if (NightModelManager.getInstance().isCurrentNightModel(this)) {
NightModelManager.getInstance().applyDayModel(this);
} else {
NightModelManager.getInstance().applyNightModel(this);
}
}