Android 探究 LayoutInflater setFactory文章的补充

原创 2016年05月30日 11:35:56
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:appcompat-v7:22.2.1'


在文件AppCompatDelegateImplV7.java中有

    @Override
    public View createView(View parent, final String name, @NonNull Context context,
            @NonNull AttributeSet attrs) {
        final boolean isPre21 = Build.VERSION.SDK_INT < 21;

        if (mAppCompatViewInflater == null) {
            mAppCompatViewInflater = new AppCompatViewInflater();
        }

        // We only want the View to inherit it's context if we're running pre-v21 and...
        final boolean inheritContext = isPre21 && mSubDecorInstalled && parent != null
                // We do not want to inherit context from any decor content
                && parent.getId() != android.R.id.content
                // We do not want to inherit context if this is the root view in the layout.
                // We use parent.isAttachedToWindow() to determine this, which works because
                // an inflated layout is only added to the hierarchy AFTER it is completely
                // inflated. Thus isAttachedToWindow() will only return true if the parent
                // has not been inflated within the outer inflation call.
                && !ViewCompat.isAttachedToWindow(parent);

        return mAppCompatViewInflater.createView(parent, name, context, attrs, inheritContext,
                isPre21, /* Only read android:theme pre-L (L+ handles this anyway) */
                true /* Read read app:theme as a fallback at all times for legacy reasons */
        );
    }


在对应的AppCompatViewInflater.java中

    public final View createView(View parent, final String name, @NonNull Context context,
            @NonNull AttributeSet attrs, boolean inheritContext,
            boolean readAndroidTheme, boolean readAppTheme) {
        final Context originalContext = context;

        // We can emulate Lollipop's android:theme attribute propagating down the view hierarchy
        // by using the parent's context
        if (inheritContext && parent != null) {
            context = parent.getContext();
        }
        if (readAndroidTheme || readAppTheme) {
            // We then apply the theme on the context, if specified
            context = themifyContext(context, attrs, readAndroidTheme, readAppTheme);
        }

        // We need to 'inject' our tint aware Views in place of the standard framework versions
        switch (name) {
            case "EditText":
                return new AppCompatEditText(context, attrs);
            case "Spinner":
                return new AppCompatSpinner(context, attrs);
            case "CheckBox":
                return new AppCompatCheckBox(context, attrs);
            case "RadioButton":
                return new AppCompatRadioButton(context, attrs);
            case "CheckedTextView":
                return new AppCompatCheckedTextView(context, attrs);
            case "AutoCompleteTextView":
                return new AppCompatAutoCompleteTextView(context, attrs);
            case "MultiAutoCompleteTextView":
                return new AppCompatMultiAutoCompleteTextView(context, attrs);
            case "RatingBar":
                return new AppCompatRatingBar(context, attrs);
            case "Button":
                return new AppCompatButton(context, attrs);
            case "TextView":
                return new AppCompatTextView(context, attrs);
        }

        if (originalContext != context) {
            // If the original context does not equal our themed context, then we need to manually
            // inflate it using the name so that android:theme takes effect.
            return createViewFromTag(context, name, attrs);
        }

        return null;
    }





注意:在最新的

    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
却没有相关的AppCompatViewInflater.java文件。

参考文章:http://blog.csdn.net/lmj623565791/article/details/51503977

Android 两行代码实现换肤 从appcompat-v7原理出发

背景 换肤方案原理在网上已经很多了, 这里不再详细描述, 强迫症的我总是想让提供给别人使用的SDK尽量好用, 哪怕是给自己带来额外的工作量, 经过一段时间的奋斗, 实现了一个自我感觉良好的换肤框...
  • qq_24531461
  • qq_24531461
  • 2017-02-26 18:57:40
  • 2269

Android 导航条效果实现(六) TabLayout+ViewPager+Fragment

TabLayout一、继承结构public class TabLayout extends HorizontalScrollView 二、TabLayout的使用 1、TabLayout简单使用 T...
  • qq_33425116
  • qq_33425116
  • 2016-09-20 20:53:33
  • 16017

Android中LayoutParams总结和用法

日积月累第三周第四天。又是忙碌的一天,昨天看了两集老罗的Android 视频教程,感觉讲的很基础。继续坚持一天一集视频。今天上班接触了一下Android 的LayoutParams今天加以整理和梳理。...
  • liuhaomatou
  • liuhaomatou
  • 2014-04-03 23:53:02
  • 147779

Android 探究 LayoutInflater setFactory

转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/51503977; 本文出自:【张鸿洋的博客】 1、概述对于Layou...
  • lmj623565791
  • lmj623565791
  • 2016-05-26 08:32:37
  • 22452

android之LayoutInflater以及setFactory源码解读

android之LayoutInflater以及setFactory源码解读
  • zhongwn
  • zhongwn
  • 2016-10-29 18:52:24
  • 976

android studio使用说明

一.学习的基本配置文档,搞好各种参数的基本配置,熟练使用。 C:\Program Files\Java\jdk1.7.0_09\bin   二.problems meet...
  • wanjunyou
  • wanjunyou
  • 2014-12-21 15:56:36
  • 34338

Android 对Layout_weight属性完全解析以及使用ListView来实现表格

今天主要说的是对Layout_weight属性的完全解析,以及利用Layout_weight这个属性使用ListView来实现表格的效果,我们都知道Android里面专门有一个TableLayout来...
  • xiaanming
  • xiaanming
  • 2013-10-31 22:40:15
  • 33287

Android探究之LayoutInflater setFactory

转载自:http://blog.csdn.net/lmj623565791/article/details/51503977 1、概述 对于LayoutInflater setFactor...
  • qq_35559358
  • qq_35559358
  • 2017-06-26 09:07:06
  • 160

探究 LayoutInflater setFactory

1 概述    对于LayoutInflater setFactory,平时我们很少用到这个API,但是这个API我觉得还是有学习的必要的,能够很多意象不到的问题,准备围绕这方面编写一系列的文章。 ...
  • fwt336
  • fwt336
  • 2016-11-21 13:44:56
  • 122

Android问题集锦之二十一:No resource found that matches the given name

在相对布局中,若是用到android:layout_above属性,并且其后id之前没有出现过,那么需要这样写:android:layout_above="@+id/vidAdd_ButtonGrou...
  • lincyang
  • lincyang
  • 2014-03-11 21:21:24
  • 42383
收藏助手
不良信息举报
您举报文章:Android 探究 LayoutInflater setFactory文章的补充
举报原因:
原因补充:

(最多只允许输入30个字)