自定义实现个Factory,可以用来解析自定义的属性。
public interface Factory {
/**
* Hook you can supply that is called when inflating from a LayoutInflater.
* You can use this to customize the tag names available in your XML
* layout files.
*
* <p>
* Note that it is good practice to prefix these custom names with your
* package (i.e., com.coolcompany.apps) to avoid conflicts with system
* names.
*
* @param name Tag name to be inflated.
* @param context The context the view is being created in.
* @param attrs Inflation attributes as specified in XML file.
*
* @return View Newly created view. Return null for the default
* behavior.如果返回一个view, 那么就会直接加入到原有View树中去。 如果返回null,则会走原来类似于onCreate的方法。
*/
public View onCreateView(String name, Context context, AttributeSet attrs);
}

LayoutInflater.Factory这个值设置到LayoutInflater中,而LayoutInflater的获得又是跟谁Context而来的。也就是说相同的Context有着相同的LayoutInflater,那就可以重用相同的LayoutInflater.factory

在BaseActivity中加入自己的Factory

     mLayoutMode = new BDLayoutMode(); // 针对该Activity的一些存储
mLayoutInflateFactory = new BDLayoutInflateFactory(); //自定义的LayoutInflateFactory
mLayoutInflateFactory.setViewMode(mLayoutMode);
getLayoutInflater().setFactory(mLayoutInflateFactory); // 给该Activitry设置factory

这样在BDLayoutInflateFactory中就可以自定义解析自己关心的值了。

在BaseActivity的OnResume中开始,遍历每一个控件。

LayoutInflater.Factory的夜间模式的更多相关文章

  1. 小菜学习设计模式(三)—工厂方法(Factory Method)模式

    前言 设计模式目录: 小菜学习设计模式(一)—模板方法(Template)模式 小菜学习设计模式(二)—单例(Singleton)模式 小菜学习设计模式(三)—工厂方法(Factory Method) ...

  2. android夜间模式实现

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

  3. DKNightVersion 的实现 --- 如何为 iOS 应用添加夜间模式

    在很多重阅读或者需要在夜间观看的软件其实都会把夜间模式当做一个 App 所需要具备的特性. 而如何在不改变原有的架构, 甚至不改变原有的代码的基础上, 就能为应用优雅地添加夜间模式就成为一个在很多应用 ...

  4. WPF窗口阴影和夜间模式的实现

    窗口阴影 实现 因项目需要给用户一定提示,设计师建议在鼠标进入时显示窗口阴影,离开时取消窗口阴影. 很自然,都会想到直接在窗口的内容或者自定义窗口的最外层元素上加效果.示例如下: <Grid&g ...

  5. WP8版微信5.4发布 新增夜间模式 暂没小视频

    经过近一个月的内测,WP8版的微信终于更新了v 5.4版本.新增聊天中的照片墙.识别图片二维码.夜间模式等功能,还对资源占用情况进行了优化,让程序可以更流畅的在低配置设备上运行. 不过,WP8版微信5 ...

  6. 设计模式学习之简单工厂(Simple Factory,创建型模式)(1)

    简单工厂(Simple Factory,创建型模式) 第一步: 比如我们要采集苹果和香蕉,那么我们需要创建一个Apple类和Banana类,里面各自有采集方法get(),然后通过main方法进行调用, ...

  7. android简单的夜间模式

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

  8. Android白天/夜间模式Day/Night Mode标准原生SDK实现

     Android白天/夜间模式Day/Night Mode标准原生SDK实现 章节A:Android实现白天/夜间模式主要控制器在于UiModeManager,UiModeManager是Andr ...

  9. 工厂方法(Factory Method)模式

    一.工厂方法(Factory Method)模式 工厂方法(FactoryMethod)模式是类的创建模式,其用意是定义一个创建产品对象的工厂接口,将实际创建工作推迟的子类中. 工厂方法模式是简单工厂 ...

随机推荐

  1. AngularJS初始化普通数组和对象数组

    普通数组: ng-init="persons=['john','jack']" 对象数组: ng-init="persons=[{name:'john',age:20}, ...

  2. .NET,Cookie,写Cookie,取Cookie

    Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...

  3. Struts2 - Interceptor中取得ActionName、Namespace、Method

    在Struts2的Interceptor中取得当前执行对应的ActionName.Namespace.Method方法: 可以使用: System.out.println(invocation.get ...

  4. LintCode "Previous Permutation"

    A reverse version of the Dictionary algorithm :) If you AC-ed "Next Permutation II", copy ...

  5. LintCode "Sliding Window Median" & "Data Stream Median"

    Besides heap, multiset<int> can also be used: class Solution { void removeOnly1(multiset<in ...

  6. 黄聪:Dsicuz x2.5、X3、X3.2如何去掉域名后面的/forum.php

    Dsicuz x2.5去掉域名后面的/forum.php 1, 后台--全局--域名设置--应用域名--设置默认域名为访问域名就可以,如:www.xxxxx.com 上面2种方法都可以去掉域名后面的/ ...

  7. 8. redis的主从复制和sentinal

    一. redis主从复制(读写分离) redis的主从复制分为两类节点:1个master和多个slave,master进行读写操作,slav进行只读操作 启动步骤: 主节点照常启动,slave节点启动 ...

  8. duplicate symbols

    duplicate symbol _mCollecatView in: /Users/Rubert/Library/Developer/Xcode/DerivedData/ChengDuHidengD ...

  9. Scala第三章学习笔记

    换行后的左大括号造成的问题: class FooHolder { def foo() { println("foo was called") } } Scala认为def foo( ...

  10. hdu 5698 瞬间移动(排列组合)

    这题刚看完,想了想,没思路,就题解了 = = 但不得不说,找到这个题解真的很强大,链接:http://blog.csdn.net/qwb492859377/article/details/514781 ...