GithubHelp home page GithubHelp logo

zhangkun6 / nightmodel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from achenglike/nightmodel

0.0 1.0 0.0 137 KB

a night model lib for easy change app's night theme.

License: Apache License 2.0

Java 100.00%

nightmodel's Introduction

NightModel

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

中文README

Thanks!

require

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

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. 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

nightmodel's People

Contributors

achenglike avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.