zoukankan      html  css  js  c++  java
  • LayoutInflater.Factory的夜间模式

    自定义实现个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中开始,遍历每一个控件。

  • 相关阅读:
    Springboot中enable注解
    java消息队列--ActiveMQ,RabbitMQ入门
    java中的静态和动态代理Proxy
    java源码中的注解
    java中jdbc源码解读
    sql脚本练习
    spring boot中的jave注解学习
    thymeleaf入门和学习
    职场经验:互联网公司有哪些“潜规则”?职场萌新一定要注意了!
    C/C++编程笔记:C语言错误处理方法!如何更好地处理程序的错误?
  • 原文地址:https://www.cnblogs.com/xitang/p/3556630.html
Copyright © 2011-2022 走看看