1.记录个最简单的夜间模式的实现

2.styles.xml

  <style name="DayTheme" parent="AppTheme">
<item name="color_title">@color/title_bai</item>
<item name="color_background">@drawable/bg01</item>
</style> <style name="NightTheme" parent="AppTheme">
<item name="color_title">@color/title_ye</item>
<item name="color_background">@drawable/bg02</item>
</style> <style name="FragmentTheme1" parent="AppTheme">
<item name="fragmentcolor_title">@color/fragment_textcolor1</item>
</style>

3.colors.xml

    <color name="title_bai">#000000</color>
<color name="title_ye">#ffffff</color>
<color name="background_bai">#ffffff</color>
<color name="background_ye">#8e7d7d</color>
<color name="fragment_textcolor1">#D43333</color>
<color name="fragment_textcolor2">#71C41F</color>

4.arrts.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> <attr name="color_title" format="color" />
<attr name="color_background" format="color" />
<attr name="fragmentcolor_title" format="color" /> </resources>

  

5.main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/color_background"
tools:context="com.example.guoxw.myapplication.MainActivity"
android:weightSum="1"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"> <Button
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textColor="?attr/color_title"
android:text="fragment1"/>
<Button
android:id="@+id/btn2"
android:layout_width="0dp"
android:layout_weight="1"
android:textColor="?attr/color_title"
android:layout_height="match_parent"
android:text="fragment2"/>
<Button
android:id="@+id/btn3"
android:layout_width="0dp"
       android:textColor="?attr/color_title"

android:layout_weight="1"
android:layout_height="match_parent"
android:text="activity2"/>
<Button
android:id="@+id/btn4"
android:layout_width="0dp"
android:textColor="?attr/color_title"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="切换"/>
</LinearLayout> <FrameLayout
android:id="@+id/fragmentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?actionBarSize"
android:layout_marginTop="?actionBarSize" />  
</LinearLayout>

6.java-activity

  protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Constant.isDay) {
this.setTheme(R.style.DayTheme);
} else {
this.setTheme(R.style.NightTheme);
}
setContentView(R.layout.activity_main);
}

7.java --fragment

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Context ctxWithTheme = new ContextThemeWrapper(getActivity().getApplicationContext(),R.style.FragmentTheme1);
LayoutInflater localLayoutInflater = inflater.cloneInContext(ctxWithTheme);
ViewGroup rootView = (ViewGroup)localLayoutInflater.inflate(R.layout.fragment_fragment1, null, false); //view=inflater.inflate(R.layout.fragment_fragment1, container, false); return rootView;
}

8.链接:

http://pan.baidu.com/s/1eSiU42Q

android夜间模式切换的更多相关文章

  1. android夜间模式实现

    一.概述 android夜间模式实现分为两大类 重启activity的实现 不重启activity的实现 二.正文 1.重启activity实现夜间模式[在界面文件中的实现部分] 1.1在attrs. ...

  2. Android 夜间模式changeskin小结

    @author vivian8725118 @CSDN http://blog.csdn.net/vivian8725118 @简书 http://www.jianshu.com/p/832e9776 ...

  3. Android夜间模式的几种实现

    一.直接修改widget颜色,这种方式实现起来最简单,但需要每个控件都去修改,太过复杂.例如: /** * 相应交互,修改控件颜色 * @param view */public void onMeth ...

  4. Android 高级UI设计笔记24:Android 夜间模式之 WebView 实现白天 / 夜间阅读模式 (使用JavaScript)

    1. 问题引入: 前面我们是使用方法 降低屏幕亮度(不常用) 和 替换theme,两者都是针对Activity的背景进行白天.夜间模式的交换,但是如果我们显示的是Html的内容,这个时候改怎么办? 分 ...

  5. Android 高级UI设计笔记23:Android 夜间模式之 两种常用方法(降低屏幕亮度+替换theme)

    1. 夜间模式 所谓的夜间模式,就是能够根据不同的设定,呈现不同风格的界面给用户,而且晚上看着不伤眼睛.特别是一些新闻类App实现夜间模式是非常人性化的,增强用户体验. 2. 我根据网上的资料 以及自 ...

  6. Android 夜间模式的实现

    package com.loaderman.daynightdemo; import android.os.Bundle; import android.support.v7.app.AppCompa ...

  7. android简单的夜间模式

    现在android项目values下打 attrs.xml <?xml version="1.0" encoding="utf-8"?> <r ...

  8. Android实现夜间模式

    如今非常多App都有夜间模式,特别是阅读类的App.夜间模式如今已经是阅读类App的标配了,其实,日间模式与夜间模式就是给App定义并应用两套不同颜色的主题,用户能够自己主动或者手动的开启,今天用An ...

  9. Android 利用an框架快速实现夜间模式的两种套路

    作者:Bgwan链接:https://zhuanlan.zhihu.com/p/22520818来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 网上看到过大多实现夜间模 ...

随机推荐

  1. 写给VC++ Windows开发的初学者 一片不错的博文

    不知不觉2010年都过了半年了,想来我学C语言已经12个年头了(从1998年开始),用VC++也有11年了,最早使用Turbo C2.0 ,也学过汇编,后来使用Borland C++3.0 .Micr ...

  2. 安装mysql-python的遇到的问题

    最近更新环境后遇到安装mysql-python的问题,感觉挺折腾的,记录一下. 安装mysql-python的时候一直提示下面的错误 _mysql.c() : fatal error C1083: C ...

  3. 动漫绘画软件优动漫PAINT最近所用文件

    在使用优动漫PAINT的时候有时候会遇到这样的问题,近期编辑的文件找不见了,或者想要接着之前的文件进行编辑,如何快速找到这些文件呢?其实在最近所用文件中一目了,本文我们一起来看看. 如果您想接着上次未 ...

  4. &:first-of-type含义

    span { &:first-of-type { margin-right: 16px; } } &符号是scss和less里的语法,代表上一级选择器,实际编译成css就是 span: ...

  5. python二级登陆菜单

    """ 1.三级菜单 注册 登陆 注销 2.进入每一个一级菜单,都会有下一级的菜单"""user_item = dict()try: whi ...

  6. windows端口被占用解决办法

    1.查找端口 netstat -ano | findstr 端口号 2.进程列表并查找相应的进程 tasklist |findstr 进程号 3.杀死进程 taskkill /f /t /im 进程名 ...

  7. MySQL-----笔记3:存储引擎

    1.存储引擎: https://zhidao.baidu.com/question/1049565846666168579.html MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技 ...

  8. docker-compose,docker-machine,docker swarm 的简单总结

    1.docker-compose: 用来在单机上启动一组应用服务.这个服务中可能包含有很多应用,比如你的app服务,redis,mysql,等等. (1)我们需要先创建好docker-compose的 ...

  9. 基于ALSA的WAV播放和录音程序

    http://blog.csdn.net/azloong/article/details/6140824 这段时间在探索ALSA架构,从ALSA Core到ALSA Lib,再到Android Aud ...

  10. 《黑白团团队》第八次团队作业:Alpha冲刺 第五天

    项目 内容 作业课程地址 任课教师首页链接 作业要求 团队项目 填写团队名称 黑白团团队 填写具体目标 认真负责,完成项目 团队项目Github仓库地址链接. 第五天 日期:2019/6/19 成员 ...