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来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 网上看到过大多实现夜间模 ...
随机推荐
- Linux date命令的用法(转)
1.命令:date 2.命令功能:date 可以用来显示或设定系统的日期与时间. 3.命令参数 -d<字符串>:显示字符串所指的日期与时间.字符串前后必须加上双引号: -s<字符串& ...
- WIN10打开网络共享文件夹提示0x80004005怎么解决?(转载)
发布时间:2018-07-04 12:48 来源:www.pipimp3.com 作者:笔记本系统 WIN10打开网络共享文件夹提示0x80004005怎么解决?针对这个问题,小编整理了方案,有兴趣的 ...
- C语言提高 (4) 第四天 数组与数组作为参数时的数组指针
1昨日回顾 const int 和 int const是一样的 const char *p;值不变 char * const p; 指针不能变 编译器对参数的退化: 第三种模型: 三级指针 三级指针局 ...
- [SDOI2016]数字配对(费用流+贪心+trick)
重点是如何找到可以配对的\(a[i]\)和\(a[j]\). 把\(a[i]\)分解质因数.设\(a[i]\)分解出的质因数的数量为\(cnt[i]\). 设\(a[i]\geq a[j]\) 那么\ ...
- nyoj11-奇偶数分离
奇偶数分离 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 有一个整型偶数n(2<= n <=10000),你要做的是:先把1到n中的所有奇数从小到大输出,再 ...
- HTML5学习(一)
HTML5学习 HTML5的基本结构 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content ...
- Swoole 同步模式与协程模式的对比
在现代化 PHP 高级开发中,Swoole 为 PHP 带来了更多可能,如:常驻内存.协程,关于传统的 Apache/FPM 模式与常驻内存模式(同步)的巨大差异,之前我做过测试,大家能直观的感受到性 ...
- mknod指令详解
mknod - make block or character special filesmknod [OPTION]... NAME TYPE [MAJOR MINOR] option 有用的 ...
- NOIP2018提高组金牌训练营——动态规划专题
NOIP2018提高组金牌训练营——动态规划专题 https://www.51nod.com/Live/LiveDescription.html#!#liveId=19 多重背包 二进制优化转化成01 ...
- Top English interview Q&A
http://www.hjenglish.com/new/p581292/ vocabulary endeavour [ɪn'devər] relevant ['reləvənt] , efficie ...