最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 實現(xiàn)夜間模式的快速簡單方法實例詳解

 更新時間:2016年09月15日 10:20:17   作者:Wei_Leng  
這篇文章主要介紹了Android 實現(xiàn)夜間模式的快速簡單方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

ChangeMode

項目地址:ChangeMode

Implementation of night mode for Android.

用最簡單的方式實現(xiàn)夜間模式,支持ListView、RecyclerView。

Preview

ChangeMode

Usage xml

android:background="?attr/zzbackground"
app:backgroundAttr="zzbackground"http://如果當(dāng)前頁面要立即刷新,這里傳入屬性名稱 比如 R.attr.zzbackground 傳 zzbackground 即可
android:textColor="?attr/zztextColor"
app:textColorAttr="zztextColor"http://如需立即刷新頁面效果 同上

java

@Override
protected void onCreate(Bundle savedInstanceState) {
//1. 在要立即切換效果的頁面調(diào)用此方法
ChangeModeController.getInstance().init(this,R.attr.class).setTheme(this, R.style.DayTheme, R.style.NightTheme);
//在其他頁面調(diào)用此方法 
//ChangeModeController.setTheme(this, R.style.DayTheme, R.style.NightTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//添加額外 view 至夜間管理
// ChangeModeController.getInstance().addBackgroundColor(toolbar, R.attr.colorPrimary);
//ChangeModeController.getInstance().addBackgroundDrawable(view,R.attr.colorAccent);
// ChangeModeController.getInstance().addTextColor(view,R.attr.colorAccent);
//2. 設(shè)置切換
//ChangeModeController.changeDay(this, R.style.DayTheme);
//ChangeModeController.changeNight(this, R.style.NightTheme);
}
@Override
protected void onDestroy() {
super.onDestroy();
//3. 在 onDestroy 調(diào)用
ChangeModeController.onDestory();
}

詳細(xì)操作描述

第一步:自定義屬性

<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="zzbackground" format="color|reference"/>
<attr name="zzbackgroundDrawable" format="reference"/>
<attr name="zztextColor" format="color"/>
<attr name="zzItemBackground" format="color"/>
</resources>

第二步:配置夜間 style 文件

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>
</style>
<!--日間模式 -->
<style name="DayTheme" parent="AppTheme">
<item name="zzbackground">@color/dayBackground</item>
<item name="zzbackgroundDrawable">@drawable/ic_launcher</item>
<item name="zztextColor">@color/dayTextColor</item>
<item name="zzItemBackground">@color/dayItemBackground</item>
</style>
<!--夜間模式 -->
<style name="NightTheme" parent="AppTheme">
<item name="zzbackground">@color/nightBackground</item>
<item name="zzbackgroundDrawable">@color/nightBackground</item>
<item name="zztextColor">@color/nightTextColor</item>
<item name="zzItemBackground">@color/nightItemBackground</item>

<item name="colorPrimary">@color/colorPrimaryNight</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkNight</item>
<item name="colorAccent">@color/colorAccentNight</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

為相關(guān)屬性設(shè)置對應(yīng)模式的屬性值:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dayBackground">#F2F4F7</color>
<color name="dayTextColor">#000</color>
<color name="dayItemBackground">#fff</color>
<color name="nightItemBackground">#37474F</color>
<color name="nightBackground">#263238</color>
<color name="nightTextColor">#fff</color>
</resources>

第三步:在布局文件中配置使用對應(yīng)屬性

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="?attr/zzbackground"
app:backgroundAttr="zzbackground"
tools:context="com.thinkfreely.changemode.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:backgroundAttr="colorPrimary"
app:titleTextColor="?attr/zztextColor"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<Button
android:layout_width="match_parent"
android:layout_height="120dp"
android:gravity="center"
android:textColor="?attr/zztextColor"
app:textColorAttr="zztextColor"
android:background="?attr/zzItemBackground"
app:backgroundAttr="zzItemBackground"
android:padding="10dp"
android:layout_marginBottom="8dp"
android:textSize="22sp"
android:textAllCaps="false"
android:text="夜間模式切換 by Mr.Zk" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</LinearLayout>

注意textColorAttr、backgroundAttr、backgroundDrawableAttr三個屬性。如需當(dāng)前頁面立即刷新,需填加相應(yīng)屬性。

屬性 描述

textColorAttr 修改字體顏色時設(shè)置。如 R.attr.zztextColor 傳 zztextColor 即可。例:app:textColorAttr="zztextColor"
backgroundAttr 修改背景顏色/背景圖片時設(shè)置。同上。例: app:backgroundAttr="zzbackground"
backgroundDrawableAttr 修改背景顏色/背景圖片時設(shè)置。同上。例: app:backgroundDrawableAttr="zzbackground"

第四步:頁面調(diào)用 java 代碼

@Override
protected void onCreate(Bundle savedInstanceState) {
//1. 在要立即切換效果的頁面調(diào)用此方法
ChangeModeController.getInstance().init(this,R.attr.class).setTheme(this, R.style.DayTheme, R.style.NightTheme);
//在其他頁面調(diào)用此方法 
//ChangeModeController.setTheme(this, R.style.DayTheme, R.style.NightTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//2.設(shè)置切換夜間活日間模式
//ChangeModeController.changeDay(this, R.style.DayTheme);//切換日間模式
//ChangeModeController.changeNight(this, R.style.NightTheme);//切換夜間模式
}
@Override
protected void onDestroy() {
super.onDestroy();
//3. 在 onDestroy 調(diào)用
ChangeModeController.onDestory();
}

代碼調(diào)用三步,即可開始夜間之旅。 如果頁面有新創(chuàng)建的視圖要加入夜間模式控制,代碼調(diào)用:

//添加額外 view 至夜間管理
// ChangeModeController.getInstance().addBackgroundColor(toolbar, R.attr.colorPrimary);
//ChangeModeController.getInstance().addBackgroundDrawable(view,R.attr.colorAccent);
// ChangeModeController.getInstance().addTextColor(view,R.attr.colorAccent);

如果在改變夜間模式時有其他非標(biāo)準(zhǔn)定義的屬性時,可在ChangeModeController.changeDay或ChangeModeController.changeNight之后調(diào)用如下代碼給相關(guān)屬性賦值:

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.

以上所述是小編給大家介紹的Android 實現(xiàn)夜間模式的快速簡單方法實例詳解,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的,在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android WindowManger的層級分析詳解

    Android WindowManger的層級分析詳解

    這篇文章主要介紹了Android WindowManger的層級分析詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Android?中TextureView和SurfaceView的屬性方法及示例說明

    Android?中TextureView和SurfaceView的屬性方法及示例說明

    這篇文章主要介紹了Android?中TextureView和SurfaceView的屬性方法及示例說明,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • Android如何自定義View實現(xiàn)橫向的雙水波紋進(jìn)度條

    Android如何自定義View實現(xiàn)橫向的雙水波紋進(jìn)度條

    最近有個需求需要實現(xiàn)自定義加載進(jìn)度條,于是深入研究了一下,這篇文章主要給大家介紹了關(guān)于Android如何自定義View實現(xiàn)橫向的雙水波紋進(jìn)度條的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • 深入android中The connection to adb is down的問題以及解決方法

    深入android中The connection to adb is 

    本篇文章是對android中The connection to adb is down的問題以及解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android開發(fā)之merge結(jié)合include優(yōu)化布局

    Android開發(fā)之merge結(jié)合include優(yōu)化布局

    這篇文章主要為大家詳細(xì)介紹了Android開發(fā)之merge結(jié)合include優(yōu)化布局,感興趣的朋友可以參考一下
    2016-06-06
  • Android實現(xiàn)有道辭典查詢功能實例詳解

    Android實現(xiàn)有道辭典查詢功能實例詳解

    這篇文章主要介紹了Android實現(xiàn)有道辭典查詢功能的方法,結(jié)合實例形式較為詳細(xì)的分析了Android基于有道詞典查詢功能的原理與具體實現(xiàn)技巧,需要的朋友可以參考下
    2016-10-10
  • Android開發(fā)之項目模塊化實踐教程

    Android開發(fā)之項目模塊化實踐教程

    這篇文章主要給大家介紹了關(guān)于Android開發(fā)之項目模塊化的相關(guān)資料,文中通過示例代碼給各位Android開發(fā)者們介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)下吧。
    2017-09-09
  • Android中實現(xiàn)在矩形框中輸入文字顯示剩余字?jǐn)?shù)的功能

    Android中實現(xiàn)在矩形框中輸入文字顯示剩余字?jǐn)?shù)的功能

    在矩形輸入框框中輸入文字顯示剩余字?jǐn)?shù)的功能在app開發(fā)中經(jīng)常會見到,今天小編就通過實例代碼給大家分享android實現(xiàn)輸入框提示剩余字?jǐn)?shù)功能,代碼簡單易懂,需要的朋友參考下吧
    2017-04-04
  • Android實現(xiàn)單選與多選對話框的代碼

    Android實現(xiàn)單選與多選對話框的代碼

    這篇文章主要介紹了Android實現(xiàn)單選與多選對話框的代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-01-01
  • Android實現(xiàn)美團下拉功能

    Android實現(xiàn)美團下拉功能

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)美團下拉功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10

最新評論

崇信县| 德保县| 吉安县| 秦皇岛市| 阳西县| 吴桥县| 囊谦县| 彭阳县| 临城县| 保山市| 福安市| 永春县| 通许县| 论坛| 新绛县| 通江县| 左云县| 得荣县| 大宁县| 牙克石市| 永州市| 新兴县| 昌平区| 寻乌县| 合川市| 基隆市| 秦皇岛市| 吉林省| 抚远县| 松阳县| 淳安县| 集安市| 勐海县| 夏河县| 泽普县| 红安县| 西丰县| 凤冈县| 抚远县| 隆德县| 东乌珠穆沁旗|