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来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 网上看到过大多实现夜间模 ...
随机推荐
- iphone通讯录的备份与恢复
最近在做iOS系统通讯录备份到服务器,并且可以从服务器中下载备份文件恢复到手机的功能,部分实现细节记录如下. 将iphone系统通讯录生成.vcf文件 ABAddressBookRef address ...
- UWP添加数字证书导出安装包本地安装
先生成一个简单的HelloWorld应用程序 <Page x:Class="HelloWorld.MainPage" xmlns="http://schemas.m ...
- BZOJ 3940: [Usaco2015 Feb]Censoring AC自动机_栈
Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...
- C++基础 (4) 第四天 this指针 全局函数和成员函数 友元 操作符重载
1static强化练习-仓库进货和出货 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; c ...
- MVC架构之delegate
Qt的MVC架构可以实现很多数据显示的功能,本次主要对代理进行一个总结: 重实现QStyledItemDelegate类,实现自定义类. (1)ComboxDelegate.h #ifndef COM ...
- [luogu 1270] “访问”美术馆 (树形dp)
传送门 Description 经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动.艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室.Peer知道每 ...
- JavaScript CSS 实现简单的 TAB 标签切换
使用CSS隐藏所有tab页,然后使用JavaScript给选中的元素对应ID的tab页设置class="active"类来显示该元素,以此实现tab切换. 如鼠标放置到shwww时 ...
- 2019-03-28 SQL Server select 1
select 1 是比select *更有效率的写法 因为它不返回具体的数据记录,而是返回n行的1 select 1 from studentsselect class,count(1) as pax ...
- 有关elasticsearch分片策略的总结
最近在优化部分业务的搜索吞吐率,结合之前优化过写请求的经验,想和大家讨论下我对es分片在不同场景下的分配策略的思路 原先普通索引我的分片策略是: 主分片=节点数,副本=1,这样可以保证业务数据一定 ...
- spring的几个重要类和接口
1.datasource接口是javax.sql包下的接口,不是spring,是javax.sql下的 datasource接口有个重要的方法getConnection()方法 Connection ...