百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

NightModel

> 编程语言
开源

一个夜间模型库,可轻松更改应用程序的夜间主题。

190 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个夜间模型库,可轻松更改应用程序的夜间主题。

NightModel

a night model lib for easy change app's night theme. Based on official night model and need't restart Activity.

中文README

Thanks!

  • ChangeSkin 张鸿洋
  • Blog 张鸿洋
  • Android换肤技术总结 markzhai

require

  • support appcompat 23.2.0 or above
  • activity extends AppCompatActivity
  • follow Android official nigh model guidance

import

  1. Add it in your root build.gradle at the end of repositories:
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  1. Add the dependency
	dependencies {
	        compile 'com.github.achenglike:NightModel:x.x'
	}

use

  1. set NightModel in Application

    public class AppApplication extends Application {
    
    @Override
    public void onCreate() {
        super.onCreate();
        NightModelManager.getInstance().init(this);
        ...
    }
    }
    
  2. attach and detach in Activity which need refresh, not every 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. for stop Activity restart, we need config configChanges="uiMode" in Androidmanifest.xml

    
    
  4. call night/day method

    private void changeNightModel() {
       if (NightModelManager.getInstance().isCurrentNightModel(this)) {
        NightModelManager.getInstance().applyDayModel(this);
    } else {
        NightModelManager.getInstance().applyNightModel(this);
         }
    }

warn

  1. this lib used for resolving the problem that official night model can not refresh started Activities. So, only attach and detach in Activities that need refresh. It's a supplementary lib for official night model.

  2. When create View dynamically in attached Activity with code, you should write like this:

    View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_layout, parentView, false);

    because the lib need cache this View, use LayoutInflater.from(MainActivity.this) will use the proxy LayoutInflaterFactory create this View and cache it

  3. style:@style/xx just support TextView (android:textColor or android:textSize) now

  4. this lib version 2.1 and before support version 26 and below 26.

  5. this lib version 2.2 and later only support android support lib version 26 and later.

  6. if we set a selector as background for View, night mode not work.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言