android夜间模式切换
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夜间模式切换的更多相关文章
- android夜间模式实现
一.概述 android夜间模式实现分为两大类 重启activity的实现 不重启activity的实现 二.正文 1.重启activity实现夜间模式[在界面文件中的实现部分] 1.1在attrs. ...
- Android 夜间模式changeskin小结
@author vivian8725118 @CSDN http://blog.csdn.net/vivian8725118 @简书 http://www.jianshu.com/p/832e9776 ...
- Android夜间模式的几种实现
一.直接修改widget颜色,这种方式实现起来最简单,但需要每个控件都去修改,太过复杂.例如: /** * 相应交互,修改控件颜色 * @param view */public void onMeth ...
- Android 高级UI设计笔记24:Android 夜间模式之 WebView 实现白天 / 夜间阅读模式 (使用JavaScript)
1. 问题引入: 前面我们是使用方法 降低屏幕亮度(不常用) 和 替换theme,两者都是针对Activity的背景进行白天.夜间模式的交换,但是如果我们显示的是Html的内容,这个时候改怎么办? 分 ...
- Android 高级UI设计笔记23:Android 夜间模式之 两种常用方法(降低屏幕亮度+替换theme)
1. 夜间模式 所谓的夜间模式,就是能够根据不同的设定,呈现不同风格的界面给用户,而且晚上看着不伤眼睛.特别是一些新闻类App实现夜间模式是非常人性化的,增强用户体验. 2. 我根据网上的资料 以及自 ...
- Android 夜间模式的实现
package com.loaderman.daynightdemo; import android.os.Bundle; import android.support.v7.app.AppCompa ...
- android简单的夜间模式
现在android项目values下打 attrs.xml <?xml version="1.0" encoding="utf-8"?> <r ...
- Android实现夜间模式
如今非常多App都有夜间模式,特别是阅读类的App.夜间模式如今已经是阅读类App的标配了,其实,日间模式与夜间模式就是给App定义并应用两套不同颜色的主题,用户能够自己主动或者手动的开启,今天用An ...
- Android 利用an框架快速实现夜间模式的两种套路
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/22520818来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 网上看到过大多实现夜间模 ...
随机推荐
- UVa 1585 待解决
是在遇到第一个ooxx的时候会出错,会少算一个1 #include<stdio.h> int main() { int i,k=0,sum=0; char a[100]={"oo ...
- Dynamics CRM Online 快速的debug 方法
这里的前提想大家了解一下. Dynamics 365 online的产品的session是30分钟 timeout. 如果你logout之后, session还是会储存在服务器端不会release. ...
- SaltStact自动化运维工具03
存储位置 类型 采集方式 场景Grains minion 静态 minion启动时,可以刷新 1.获取信息 2.匹配pil ...
- python tips: for循环的小问题
在python中,用for对列表进行遍历的时候,迭代器中维护的是列表的索引而不是列表的元素.也就是说,for循环是对索引进行迭代,如果在for循环过程中修改了列表,迭代出来的值是新列表的索引位置,如果 ...
- 研究发现:TLS1.3中的 TLS 对话恢复机制可以追踪用户
由于隐私浏览器技术的日渐成熟,网站越来越无法通过 Cookie 和网页浏览器特征来追踪用户,但道高一尺魔高一丈,现在这些网站会用 TLS 1.3 中的 TLS 对话恢复机制追踪用户. 你以为禁用浏览器 ...
- 莫烦大大TensorFlow学习笔记(8)----优化器
一.TensorFlow中的优化器 tf.train.GradientDescentOptimizer:梯度下降算法 tf.train.AdadeltaOptimizer tf.train.Adagr ...
- 探索JS引擎工作原理 (转)
这篇文章从相对底层的角度介绍了js引擎的工作 引入了 静态作用域 执行环境上下文(context) 等概念 , http://www.cnblogs.com/onepixel/p/5090799.ht ...
- PHP 使用 Kafka 安装拾遗
最近项目开发中需要使用 Kafka 消息队列.经过检索,PHP下面有通用的两种方式来调用 Kafka . php-rdkafka 扩展 以 PHP 扩展的形式进行使用是非常高效的.另外,该项目也提供了 ...
- mplayer configure选项中文注释
mplayer configure选项中文注释(MPlayer-1.0rc2) http://blogold.chinaunix.net/u3/104581/showart_2322466.html ...
- Dubbo&Zookeeper运行原理
Dubbo是一个分布式服务框架,Dubbo的架构如图所示: 节点角色说明: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发 ...