{"id":13643565,"url":"https://github.com/zzz40500/ThemeDemo","last_synced_at":"2025-04-21T02:30:39.175Z","repository":{"id":86557843,"uuid":"41951296","full_name":"zzz40500/ThemeDemo","owner":"zzz40500","description":"(DEPRECATED)日夜间模式切换","archived":false,"fork":false,"pushed_at":"2016-05-24T16:20:50.000Z","size":142,"stargazers_count":393,"open_issues_count":2,"forks_count":51,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-08T03:11:15.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zzz40500.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-09-05T06:15:40.000Z","updated_at":"2024-11-01T02:53:03.000Z","dependencies_parsed_at":"2023-03-04T08:01:00.307Z","dependency_job_id":null,"html_url":"https://github.com/zzz40500/ThemeDemo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzz40500%2FThemeDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzz40500%2FThemeDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzz40500%2FThemeDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzz40500%2FThemeDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zzz40500","download_url":"https://codeload.github.com/zzz40500/ThemeDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249986022,"owners_count":21356310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:01:49.338Z","updated_at":"2025-04-21T02:30:37.727Z","avatar_url":"https://github.com/zzz40500.png","language":"Java","funding_links":[],"categories":["主题样式"],"sub_categories":[],"readme":"[![Android Gems](http://www.android-gems.com/badge/zzz40500/ThemeDemo.svg?branch=master)](http://www.android-gems.com/lib/zzz40500/ThemeDemo)\n\r\n#效果图:\n\n![ThemeDemo.gif](http://upload-images.jianshu.io/upload_images/166866-f4a26bbeebb3fff9.gif?imageMogr2/auto-orient/strip)\n\n\n[Github](https://github.com/zzz40500/ThemeDemo)  \n#前面:  \n实现的原理像我微博之前的说的那样.  \n\u003e关于多主题实现的,我这里的做法是继承AppCompatActivity,置换了AppCompatDelegate中AppCompatViewInflater中的createView 方法.实现了对 xml 控件的控制.\n\n\n#实现:\n1. 实现了日夜模式的切换.(不重启 Acitivity )\n* 解决了因为快速点击 View 导致的多次响应点击事件.\n* 内部实现了 Android 5.0 的CircularReveal效果.\n\n###优点:\n布局中直接使用 Android 默认的控件就可以.在解析以后会根据控件转换成支持主题切换的控件.解放冗余的名称.\n###缺点:\n暂时不支持 Menu 级的切换.\n\n###支持属性:\nView 级:  \n`nightBackground`  \nTextView 级:  \n`nightTextColor`  \n`nightTextColorHighlight`  \n`nightTextAppearance`  \n`nightTextColorLink`  \n`nightTextColorHint`  \nListView 级:  \n`nightLVDivider`  \nLinearLayout 级别:  \n`nightDivider`  \n第三方控件支持:\n`nightBackground`  \n`nightTextColor`  \n\n\n\n\n###gradle:\n/build.gradle\n~~~\n\nrepositories {\n    maven {\n        url \"https://jitpack.io\"\n    }\n}\n~~~\n/app/build.gradle\n~~~\ncompile 'com.github.zzz40500:ThemeDemo:0.1'\n~~~\n\n##使用方法:\n####代码上\n Activity 继承MAppCompatActivity  \n####布局上\n~~~\n\u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n              xmlns:tools=\"http://schemas.android.com/tools\"\n              android:id=\"@+id/rl\"\n              android:layout_width=\"match_parent\"\n              android:layout_height=\"match_parent\"\n              android:background=\"@color/light_bg\"\n              xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n              android:orientation=\"vertical\"\n              tools:ignore=\"MissingPrefix\"\n              app:nightBackground=\"@color/night_bg\"\n              tools:context=\".MainActivity\"\u003e\n    \u003candroid.support.v7.widget.Toolbar\n        android:id=\"@+id/toolBar\"\n        android:layout_height=\"?attr/actionBarSize\"\n        android:layout_width=\"fill_parent\"\n        /\u003e\n    \u003cTextView\n        android:layout_width=\"fill_parent\"\n        android:id=\"@+id/tv\"\n        android:layout_below=\"@+id/toolBar\"\n        android:gravity=\"center\"\n        android:background=\"@color/red\"\n        android:text=\"TextView\"\n        android:textColor=\"@color/normal_black\"\n        android:textAppearance=\"@style/TextAppearance.AppCompat.Display1\"\n        android:layout_height=\"100dp\"\n        app:nightTextColor=\"@color/night_tv_color\"\n        app:nightBackground=\"@color/night_bg\"\n        /\u003e\n\n    \u003cButton\n        android:layout_below=\"@+id/tv\"\n        android:layout_width=\"fill_parent\"\n        android:text=\"Click\"\n        android:id=\"@+id/button\"\n        android:background=\"@color/button_bg\"\n        android:textColor=\"@color/normal_black\"\n        android:layout_height=\"50dp\"\n        app:nightBackground=\"@color/night_bg\"\n        /\u003e\n\n    \u003candroid.support.design.widget.FloatingActionButton\n        android:id=\"@+id/fb\"\n        android:layout_width=\"48dp\"\n        android:layout_alignParentRight=\"true\"\n        android:layout_alignParentBottom=\"true\"\n        android:layout_margin=\"16dp\"\n        android:layout_height=\"48dp\"\n        app:backgroundTint=\"#ff87ffeb\"\n        app:rippleColor=\"#33728dff\"\n        android:src=\"@mipmap/ic_launcher\"\n        android:orientation=\"vertical\" /\u003e\n\n\u003c/RelativeLayout\u003e\n~~~\n处女座在根控件加入`tools:ignore=\"MissingPrefix\"`\n\n\n####切换主题方法:\n~~~\n\n\n/**\n * \n * @param activity 当前 Activity\n * @param skinStyle Dark(夜间),Light(日间)\n * @param skinStyleChangeListener (转换监听器)\n */\nSkinCompat.setSkinStyle(Activity activity, SkinStyle skinStyle,SkinStyleChangeListener skinStyleChangeListener) \n~~~\n\n####使用CircularReveal 效果:\n5.0 上面用的是原生的 api,5.0下面才是自己的实现的方法.\n~~~\n \n\nCRAnimation crA =\n        new CircularRevealCompat(mRl).circularReveal(\n                mFloatingActionButton.getLeft() + mFloatingActionButton.getWidth() / 2, mFloatingActionButton.getTop() + mFloatingActionButton.getHeight() / 2, 0, mRl.getHeight());\n\nif (crA != null)\n    crA.start();\n~~~\n\n\n###扩展:\n支持对原生控件的解析时期替换:\n~~~\n这边很奇葩的把 TextView 变成了 EditText 控件,只是为了替换而替换.\nWidgetFactor.getInstant().setWidgetParser(new WidgetFactor.WidgetParser() {\n    @Override\n    public View parseWidget(String name, Context context, AttributeSet attrs) {\n        //布局中的名称\n        if (name.equals(\"TextView\")) {\n            return new EditText(context, attrs);\n        }\n        //返回 null 则不替换.\n        return null;\n    }\n});\n~~~\n\n\n第三方控件支持CircularReveal效果:  \n实现CircleRevealEnable这个接口:[模板](https://github.com/zzz40500/ThemeDemo/blob/master/%E6%A8%A1%E6%9D%BF)  \n\n###未来可能实现的:\n1. 实现Toolbar和 menu 的日夜间切换.\n* 替换CircularReveal算法 . \n* 出个轻量的,不带日夜间切换的库.\n\n#尾巴:  \n1. 实现原理主要是受到代码家在[Google I/O 2015 为 Android 开发者带来了哪些福利](http://www.jianshu.com/p/4f7f55471da2)里面的启发.  \n* 我在项目中也仅仅只是用在解决快速点击 View 导致的多响应,和使用CircularReveal效果.日夜间模式并没有这个需求.  \n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzz40500%2FThemeDemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzzz40500%2FThemeDemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzz40500%2FThemeDemo/lists"}