Android夜间模式切换库 NightModel

码农软件 · 软件分类 · 手机开发包 · 2019-05-04 17:43:38

软件介绍

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);
    }
}

本文地址:https://codercto.com/soft/d/5019.html

Web Design DeMYSTiFieD

Web Design DeMYSTiFieD

Willard, Wendy / 2010-11 / $ 24.86

Website Design just got a whole lot easier! This title helps you to learn the latest website development tools, techniques, and best practices. "Web Design Demystified" provides the hands-on help you ......一起来看看 《Web Design DeMYSTiFieD》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具