Detailed examples of fast and simple methods for Android to realize night mode

ChangeMode

Project address: changemode

Implementation of night mode for Android.

Implement the night mode in the simplest way, and support listview and recyclerview.

Preview

Usage xml

java

Detailed operation description

Step 1: Customize attributes

Step 2: configuration file

Set the attribute value of the corresponding mode for related attributes:

Step 3: configure and use the corresponding attributes in the layout file

Note the textcolorattr, backgroundattr, and backgrounddrawableattr attributes. If you want to refresh the current page immediately, you need to fill in the corresponding attributes.

Attribute description

Textcolorattr is set when modifying the font color. Such as r.attr Just pass zztextcolor to zztextcolor. Example: app: textcolorattr = "zztextcolor" backgroundattr setting when modifying background color / background picture. ditto. Example: app: backgroundattr = "zzbackground" backgrounddrawableattr setting when modifying background color / background picture. ditto. Example: app: backgrounddrawableattr = "zzbackground"

Step 4: call java code on the page

The code calls three steps to start the night trip. If there is a newly created view on the page to be added to the night mode control, the code calls:

If there are other non-standard defined properties when changing the night mode, you can use changemodecontroller Changeday or changemodecontroller After changeNight, the following code is called to assign the relevant attributes:

TypedValue attrTypedValue = ChangeModeController. getAttrTypedValue(this,R.attr.zztextColor); toolbar. setTitleTextColor(getResources().getColor(attrTypedValue.resourceId)); About me An Android Developer in ZhengZhou.

License ======= Copyright 2016 zhangke Licensed under the Apache License,Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,software distributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. See the License for the specific language governing permissions and limitations under the License.

The above is a detailed example of the fast and simple method for Android to realize the night mode introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for programming Xiaoqiao website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>