Java 类android.support.v4.view.LayoutInflaterCompat 实例源码

项目:simplefragment    文件:SimpleFragmentStateManager.java   
/**
 * Creates the view for the given fragment. This will trigger {@link
 * me.tatarka.simplefragment.SimpleFragment#onCreateView(LayoutInflater, ViewGroup)}
 * immediately. This will <em>not</em> occur automatically on configuration changes, you are
 * responsible for calling it again in those cases.
 *
 * @param fragment The {@code SimpleFragment} to createView.
 * @throws java.lang.IllegalArgumentException If the given fragment is null or was not added to
 *                                            this manager.
 */
public View createView(SimpleFragment fragment, LayoutInflater layoutInflater, @Nullable ViewGroup parentView) {
    if (fragment == null) {
        throw new IllegalArgumentException("SimpleFragment cannot be null.");
    }
    if (!fragments.contains(fragment)) {
        throw new IllegalArgumentException("Attempting to createView fragment that was not added: '" + fragment + "'");
    }

    if (fragment.getView() != null) {
        throw new IllegalArgumentException("Attempting to createView fragment that has already been attached.");
    }

    // To support <fragment> tags in nested layouts, we need a custom inflater.
    LayoutInflater fragmentInflater = layoutInflater.cloneInContext(activity);
    LayoutInflaterCompat.setFactory(fragmentInflater, new SimpleFragmentViewInflater(fragment.getSimpleFragmentManager()));

    return fragment.createView(fragmentInflater, parentView);
}
项目:pandroid    文件:PandroidViewFactory.java   
public static void installPandroidViewFactory(AppCompatActivity compatActivity) {
    List<LayoutInflater.Factory2> factories = new ArrayList<>();
    if (compatActivity instanceof PandroidFactoryProvider) {
        addProviderFactories((PandroidFactoryProvider) compatActivity, factories);
    }
    if (compatActivity.getApplication() instanceof PandroidFactoryProvider) {
        addProviderFactories((PandroidFactoryProvider) compatActivity.getApplication(), factories);
    }
    if (!factories.isEmpty()) {
        LayoutInflater inflater = LayoutInflater.from(compatActivity);
        if (inflater.getFactory2() == null) {
            PandroidViewFactory factory = new PandroidViewFactory(compatActivity.getDelegate(), factories);
            LayoutInflaterCompat.setFactory2(inflater, factory);
        } else {
            LogcatLogger.getInstance().w(TAG, "can't set layout inflater factory");
        }
    } else {
        LogcatLogger.getInstance().w(TAG, "Your activity or application should implement PandroidFactoryProvider to install PandroidLayoutInflaterFactory");
    }

}
项目:Overchan-Android    文件:CustomThemeHelper.java   
public static void setCustomTheme(Context context, SparseIntArray customAttrs) {
    if (customAttrs == null || customAttrs.size() == 0) {
        currentAttrs = null;
        return;
    }

    TypedValue tmp = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, tmp, true);
    int textColorPrimaryOriginal = (tmp.type >= TypedValue.TYPE_FIRST_COLOR_INT && tmp.type <= TypedValue.TYPE_LAST_COLOR_INT) ?
            tmp.data : Color.TRANSPARENT;
    int textColorPrimaryOverridden = customAttrs.get(android.R.attr.textColorPrimary, textColorPrimaryOriginal);

    try {
        processWindow(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden);
    } catch (Exception e) {
        Logger.e(TAG, e);
    }

    CustomThemeHelper instance = new CustomThemeHelper(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden);
    LayoutInflaterCompat.setFactory(instance.inflater, instance);
    currentAttrs = customAttrs;
}
项目:AndroidSkinAnimator    文件:SkinCompatActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    if (needAnimator()) {
        AnimatorManager.setConfig(new AnimatorConfig.Builder()
                .textviewVisibleAnimationType(ViewAnimatorType.AlphaHideAnimator)
                .textviewTextAnimationType(ViewAnimatorType.AlphaUpdateAnimator)
                .imageviewVisibleAnimationType(ViewAnimatorType.AlphaHideAnimator)
                .build());
    }
    LayoutInflaterCompat.setFactory(getLayoutInflater(), getSkinDelegate());
    super.onCreate(savedInstanceState);
}
项目:Android-Skin    文件:AndroidSkinHook.java   
private void hookLayoutInflater(Context context) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    try {
        Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
        field.setAccessible(true);
        field.setBoolean(layoutInflater, false);
        LayoutInflaterCompat.setFactory2(layoutInflater, AndroidSkinFactory.from(context,layoutInflater));
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
项目:revolution-irc    文件:ThemedActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory2(getLayoutInflater(), new ThemedViewFactory(this));
    mCurrentPrimaryColor = ThemeHelper.getPrimaryColor(this);
    mCurrentAccentColor = ThemeHelper.getAccentColor(this);
    super.onCreate(savedInstanceState);
    applyStatusBarColor();
    if (ThemeHelper.hasCustomPrimaryColor(this) &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setTaskDescription(new ActivityManager.TaskDescription(null, null,
                mCurrentPrimaryColor));
    }
}
项目:boohee_v5.6    文件:AppCompatDelegateImplV7.java   
public void installViewFactory() {
    LayoutInflater layoutInflater = LayoutInflater.from(this.mContext);
    if (layoutInflater.getFactory() == null) {
        LayoutInflaterCompat.setFactory(layoutInflater, this);
    } else if (!(LayoutInflaterCompat.getFactory(layoutInflater) instanceof AppCompatDelegateImplV7)) {
        Log.i("AppCompatDelegate", "The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's");
    }
}
项目:androidgithub    文件:PTActivity.java   
@Override
    protected final void onCreate(@Nullable Bundle savedInstanceState) {
        // define the IconicsLayoutInflater
        // this is compatible with calligraphy and other libs which wrap the baseContext
        LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        mActivity = this;
        mApplication = (PTApplication) getApplication();
        mBundle = getIntent().getExtras() != null ? getIntent().getExtras() : new Bundle();
        unbinder = ButterKnife.bind(this);
        mLoadingView = new LoadingView(this, getLoadingMessage());
//        loadState = (ILoadState) findViewById(R.id.load_state_view);
//        mPTLoading = new PTLoading.Builder(this)
//                .setCanceledOnTouchOutside(false)
//                .setIcon(R.drawable.button_loading_icon)
//                .setMsg(getString(R.string.loading_data))
//                .build();
//        mPTToast = new PTToast.Builder(this)
//                .setShowTime(1300)
//                .build();
        if (useEventBus())
            EventBusUtils.register(this);
        onViewCreated(savedInstanceState);
    }
项目:Android-skin-support    文件:SkinActivityLifecycle.java   
private void installLayoutFactory(Context context) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    try {
        Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
        field.setAccessible(true);
        field.setBoolean(layoutInflater, false);
        LayoutInflaterCompat.setFactory(layoutInflater, getSkinDelegate(context));
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
项目:Android-skin-support    文件:SkinCompatActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), getSkinDelegate());
    super.onCreate(savedInstanceState);
    updateStatusBarColor();
    updateWindowBackground();
}
项目:Android-skin-support    文件:SkinActivityLifecycle.java   
private void installLayoutFactory(Context context) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    try {
        Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
        field.setAccessible(true);
        field.setBoolean(layoutInflater, false);
        LayoutInflaterCompat.setFactory(layoutInflater, getSkinDelegate(context));
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
项目:CSkin    文件:BaseSkinActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    skinFactory = new SkinFactory(ApkSkin.path);
    LayoutInflaterCompat.setFactory(getLayoutInflater(), skinFactory);

}
项目:ReadMark    文件:BaseSkinActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    //在setContentView之前设置好工厂
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    LayoutInflaterCompat.setFactory(layoutInflater, this);
    SkinManager.getInstance().init(this);
    /*if (layoutInflater.getFactory() == null) {
        LayoutInflaterCompat.setFactory(layoutInflater, this);
    }*/
    super.onCreate(savedInstanceState);
}
项目:zhizhihuhu    文件:NightModelManager.java   
/**
 * this method should be called in Activity onCreate method,
 * and before method super.onCreate(savedInstanceState);
 *
 * @param activity
 */
public void attach(AppCompatActivity activity) {

    if (activity.getDelegate() instanceof LayoutInflaterFactory) {
        LayoutInflaterFactory originInflaterFactory = (LayoutInflaterFactory) activity.getDelegate();
        LayoutInflaterFactory proxyInflaterFactory = (LayoutInflaterFactory) Proxy.newProxyInstance(
                originInflaterFactory.getClass().getClassLoader(),
                new Class[]{LayoutInflaterFactory.class},
                new InflaterHandler(originInflaterFactory, activity));

        LayoutInflater layoutInflater = LayoutInflater.from(activity);
        LayoutInflaterCompat.setFactory(layoutInflater, proxyInflaterFactory);
    }
}
项目:Droid2JoyStick    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bindView();
    initView();
    setupComponent();
}
项目:NMSAlphabetAndroidApp    文件:BaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    ThemeUtil.setCustomTheme(this);
    LanguageUtil.updateLanguage(this);
    tintBars();
}
项目:GithubApp    文件:BaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    // define the IconicsLayoutInflater
    // this is compatible with calligraphy and other libs which wrap the baseContext
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));

    super.onCreate(savedInstanceState);
}
项目:WhiteRead    文件:BaseActivity.java   
public void ReplaceSystemControls() {
        LayoutInflaterCompat.setFactory(LayoutInflater.from(this), new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
//                /**
//                 * 可以在这里将系统类替换为自定义View,不要在这里做处理,到相应的类中复写该方法
//                 */
//                if (name.equals("ImageView")) {
//                    return new Button(context, attrs);
//                }
                return getDelegate().createView(parent, name, context, attrs);
            }
        });
    }
项目:NightModel    文件:NightModelManager.java   
/**
 * this method should be called in Activity onCreate method,
 * and before method super.onCreate(savedInstanceState);
 *
 * @param activity
 */
public void attach(AppCompatActivity activity) {

    if (activity.getDelegate() instanceof LayoutInflaterFactory) {
        LayoutInflaterFactory originInflaterFactory = (LayoutInflaterFactory) activity.getDelegate();
        LayoutInflaterFactory proxyInflaterFactory = (LayoutInflaterFactory) Proxy.newProxyInstance(
                originInflaterFactory.getClass().getClassLoader(),
                new Class[]{LayoutInflaterFactory.class},
                new InflaterHandler(originInflaterFactory, activity));

        LayoutInflater layoutInflater = LayoutInflater.from(activity);
        LayoutInflaterCompat.setFactory(layoutInflater, proxyInflaterFactory);
    }
}
项目:QxChangeThemeSkin    文件:QxSkinBaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    mSkinInflaterFactory = new SkinInflaterFactory();
    LayoutInflaterCompat.setFactory(getLayoutInflater(), mSkinInflaterFactory);
    super.onCreate(savedInstanceState);
    changeStatusColor();
    setContentView(layoutResoursId());
}
项目:emojiconize    文件:Emojiconize.java   
public void go() {
    checkGone();
    if (activity != null) {
        LayoutInflaterCompat.setFactory(activity.getLayoutInflater(),
                new EmojiconLayoutInflaterFactory(this));
    } else {
        emojiconize(view);
    }
    gone = true;
}
项目:ReadMark    文件:BaseSkinActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    //在setContentView之前设置好工厂
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    LayoutInflaterCompat.setFactory(layoutInflater, this);
    SkinManager.getInstance().init(this);
    /*if (layoutInflater.getFactory() == null) {
        LayoutInflaterCompat.setFactory(layoutInflater, this);
    }*/
    super.onCreate(savedInstanceState);
}
项目:simplefragment    文件:SimpleFragmentDelegate.java   
public void installViewFactory(@Nullable LayoutInflaterFactory delegateFactory) {
    this.delegateFactory = delegateFactory;
    LayoutInflater layoutInflater = LayoutInflater.from(activity);
    if (layoutInflater.getFactory() == null) {
        LayoutInflaterCompat.setFactory(layoutInflater, this);
    } else {
        Log.i(TAG, "The Activity's LayoutInflater already has a Factory installed"
                + " so we can not install AppCompat's");
    }
}
项目:FMTech    文件:AppCompatDelegateImplV7.java   
public final void installViewFactory()
{
  LayoutInflater localLayoutInflater = LayoutInflater.from(this.mContext);
  if (localLayoutInflater.getFactory() == null)
  {
    LayoutInflaterCompat.setFactory(localLayoutInflater, this);
    return;
  }
  Log.i("AppCompatDelegate", "The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's");
}
项目:FMTech    文件:Fragment.java   
public LayoutInflater getLayoutInflater(Bundle paramBundle)
{
  LayoutInflater localLayoutInflater = this.mHost.onGetLayoutInflater();
  getChildFragmentManager();
  LayoutInflaterCompat.setFactory(localLayoutInflater, this.mChildFragmentManager);
  return localLayoutInflater;
}
项目:ChangeSkin    文件:BaseSkinActivity.java   
protected void onCreate(@Nullable Bundle savedInstanceState)
{
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    LayoutInflaterCompat.setFactory(layoutInflater, this);
    super.onCreate(savedInstanceState);
    SkinManager.getInstance().addChangedListener(this);
}
项目:MyCTFWriteUps    文件:AppCompatDelegateImplV7.java   
public void installViewFactory()
{
    LayoutInflater layoutinflater = LayoutInflater.from(mContext);
    if (layoutinflater.getFactory() == null)
    {
        LayoutInflaterCompat.setFactory(layoutinflater, this);
        return;
    } else
    {
        Log.i("AppCompatDelegate", "The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's");
        return;
    }
}
项目:MyCTFWriteUps    文件:Fragment.java   
public LayoutInflater getLayoutInflater(Bundle bundle)
{
    bundle = mHost.onGetLayoutInflater();
    getChildFragmentManager();
    LayoutInflaterCompat.setFactory(bundle, mChildFragmentManager.getLayoutInflaterFactory());
    return bundle;
}
项目:Android-RobotoTextView    文件:RobotoInflater.java   
public static void attach(@NonNull Activity activity) {
    if (activity instanceof AppCompatActivity) {
        LayoutInflaterCompat.setFactory(activity.getLayoutInflater(),
                new RobotoInflater(((AppCompatActivity) activity).getDelegate(), activity.getWindow()));
    } else {
        final Window window = activity.getWindow();
        final Window.Callback callback = window.getCallback();
        LayoutInflaterCompat.setFactory(activity.getLayoutInflater(),
                new RobotoInflater(AppCompatDelegate.create(activity, StubAppCompatCallback.INSTANCE), window));
        window.setCallback(callback);
    }
}
项目:android-movies-app    文件:BaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    Icepick.restoreInstanceState(this, savedInstanceState);
}
项目:GitHub    文件:ExpandableSampleActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_collapsible);

    //style our ui
    new MaterializeBuilder().withActivity(this).build();

    //create our FastAdapter
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);

    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);

    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        if (i % 10 == 0) {
            SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
            expandableItem
                    .withName("Test " + i)
                    .withIdentifier(100 + i);

            //add subitems so we can showcase the collapsible functionality
            List<IItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 5; ii++) {
                SimpleSubItem sampleItem = new SimpleSubItem();
                sampleItem
                        .withName("-- Test " + ii)
                        .withIdentifier(1000 + ii);
                subItems.add(sampleItem);
            }
            expandableItem.withSubItems(subItems);

            items.add(expandableItem);
        } else {
            items.add(new SimpleSubItem().withName("Test " + i).withIdentifier(100 + i));
        }
    }
    fastItemAdapter.add(items);

    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);

    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
项目:MyFire    文件:ChangeModeController.java   
/**
     * 初始化夜间控制器
     * @param activity 上下文
     * @return
     */
    public ChangeModeController init(final Activity activity,final Class mClass){
        init();
        LayoutInflaterCompat.setFactory(LayoutInflater.from(activity), new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                View view = null;
                try {
                    if(name.indexOf('.') == -1){
                        if ("View".equals(name)) {
                            view = LayoutInflater.from(context).createView(name, "android.view.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.widget.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.webkit.", attrs);
                        }

                    }else{
                        if (view == null){
                            view = LayoutInflater.from(context).createView(name, null, attrs);
                        }
                    }
                    if(view != null){
                   // Log.e("TAG", "name = " + name);
                        for (int i = 0; i < attrs.getAttributeCount(); i++) {
//                            Log.e("TAG", attrs.getAttributeName(i) + " , " + attrs.getAttributeValue(i));
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND)) {
                                mBackGroundViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TWO_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_THREE_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND_DRAWABLE)) {
                                mBackGroundDrawableViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }

                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                return view;
            }
        });
        return this;
    }
项目:letv    文件:Fragment.java   
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
    LayoutInflater result = this.mHost.onGetLayoutInflater();
    getChildFragmentManager();
    LayoutInflaterCompat.setFactory(result, this.mChildFragmentManager.getLayoutInflaterFactory());
    return result;
}
项目:boohee_v5.6    文件:Fragment.java   
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
    LayoutInflater result = this.mHost.onGetLayoutInflater();
    getChildFragmentManager();
    LayoutInflaterCompat.setFactory(result, this.mChildFragmentManager.getLayoutInflaterFactory());
    return result;
}
项目:MusicX-music-player    文件:ATEUtil.java   
public static void setInflaterFactory(LayoutInflater li, Activity activity) {
    LayoutInflaterCompat.setFactory(li, new InflationInterceptor(
            activity instanceof ATEActivity ? (ATEActivity) activity : null,
            li,
            activity instanceof AppCompatActivity ? ((AppCompatActivity) activity).getDelegate() : null));
}
项目:SkinSprite    文件:SkinnableActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    LayoutInflaterCompat.setFactory(layoutInflater, this);
    super.onCreate(savedInstanceState);
}
项目:DailyNews    文件:ChangeModeController.java   
/**
     * 初始化夜间控制器
     * @param activity 上下文
     * @return
     */
    public ChangeModeController init(final Activity activity, final Class mClass){
        init();
        LayoutInflaterCompat.setFactory(LayoutInflater.from(activity), new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                View view = null;
                try {
                    if(name.indexOf('.') == -1){
                        if ("View".equals(name)) {
                            view = LayoutInflater.from(context).createView(name, "android.view.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.widget.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.webkit.", attrs);
                        }

                    }else{
                        if (view == null){
                            view = LayoutInflater.from(context).createView(name, null, attrs);
                        }
                    }
                    if(view != null){
                   // Log.e("TAG", "name = " + name);
                        for (int i = 0; i < attrs.getAttributeCount(); i++) {
//                            Log.e("TAG", attrs.getAttributeName(i) + " , " + attrs.getAttributeValue(i));
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND)) {
                                mBackGroundViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TWO_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_THREE_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND_DRAWABLE)) {
                                mBackGroundDrawableViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }

                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                return view;
            }
        });
        return this;
    }
项目:app-theme-engine    文件:ATEUtil.java   
public static void setInflaterFactory(LayoutInflater li, Activity activity) {
    LayoutInflaterCompat.setFactory(li, new InflationInterceptor(
            activity instanceof ATEActivity ? (ATEActivity) activity : null,
            li,
            activity instanceof AppCompatActivity ? ((AppCompatActivity) activity).getDelegate() : null));
}
项目:Ydkd    文件:ChangeModeController.java   
/**
     * 初始化夜间控制器
     * @param activity 上下文
     * @return
     */
    public ChangeModeController init(final Activity activity,final Class mClass){
        init();
        LayoutInflaterCompat.setFactory(LayoutInflater.from(activity), new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                View view = null;
                try {
                    if(name.indexOf('.') == -1){
                        if ("View".equals(name)) {
                            view = LayoutInflater.from(context).createView(name, "android.view.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.widget.", attrs);
                        }
                        if (view == null) {
                            view = LayoutInflater.from(context).createView(name, "android.webkit.", attrs);
                        }

                    }else{
                        if (view == null){
                            view = LayoutInflater.from(context).createView(name, null, attrs);
                        }
                    }
                    if(view != null){
                   // Log.e("TAG", "name = " + name);
                        for (int i = 0; i < attrs.getAttributeCount(); i++) {
//                            Log.e("TAG", attrs.getAttributeName(i) + " , " + attrs.getAttributeValue(i));
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND)) {
                                mBackGroundViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_TWO_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_THREE_TEXTCOLOR)) {
                                mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }
                            if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND_DRAWABLE)) {
                                mBackGroundDrawableViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
                            }

                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                return view;
            }
        });
        return this;
    }
项目:AppCompat-Extension-Library    文件:TypefaceCompatFactory.java   
public static void installViewFactory(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        LayoutInflaterCompat.setFactory(LayoutInflater.from(context),
                new TypefaceCompatFactory(context, false));
    }
}