@Override protectedvoidonCreate(@Nullable Bundle savedInstanceState) { finalAppCompatDelegatedelegate= getDelegate(); delegate.installViewFactory(); delegate.onCreate(savedInstanceState); if (delegate.applyDayNight() && mThemeId != 0) { // If DayNight has been applied, we need to re-apply the theme for // the changes to take effect. On API 23+, we should bypass // setTheme(), which will no-op if the theme ID is identical to the // current theme ID. if (Build.VERSION.SDK_INT >= 23) { onApplyThemeResource(getTheme(), mThemeId, false); } else { setTheme(mThemeId); } } super.onCreate(savedInstanceState); }
/** * @return The {@link AppCompatDelegate} being used by this Activity. */ @NonNull public AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, this); } return mDelegate; }
if (mAppCompatViewInflater == null) { mAppCompatViewInflater = newAppCompatViewInflater(); }
// We only want the View to inherit its context if we're running pre-v21 finalbooleaninheritContext= isPre21 && shouldInheritContext((ViewParent) 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 */ VectorEnabledTintResources.shouldBeUsed() /* Only tint wrap the context if enabled */ ); } @Override publicvoidinstallViewFactory() { LayoutInflaterlayoutInflater= LayoutInflater.from(mContext); if (layoutInflater.getFactory() == null) { LayoutInflaterCompat.setFactory(layoutInflater, this); } else { if (!(LayoutInflaterCompat.getFactory(layoutInflater) instanceof AppCompatDelegateImplV9)) { Log.i(TAG, "The Activity's LayoutInflater already has a Factory installed" + " so we can not install AppCompat's"); } } }
/** * Installs AppCompat's {@link android.view.LayoutInflater} Factory so that it can replace * the framework widgets with compatible tinted versions. This should be called before * {@code super.onCreate()} as so: * <pre class="prettyprint"> * protected void onCreate(Bundle savedInstanceState) { * getDelegate().installViewFactory(); * getDelegate().onCreate(savedInstanceState); * super.onCreate(savedInstanceState); * * // ... * } * </pre> * If you are using your own {@link android.view.LayoutInflater.Factory Factory} or * {@link android.view.LayoutInflater.Factory2 Factory2} then you can omit this call, and instead call * {@link #createView(android.view.View, String, android.content.Context, android.util.AttributeSet)} * from your factory to return any compatible widgets. */ publicabstractvoidinstallViewFactory();
/** * This should be called from a * {@link android.view.LayoutInflater.Factory2 LayoutInflater.Factory2} in order * to return tint-aware widgets. * <p> * This is only needed if you are using your own * {@link android.view.LayoutInflater LayoutInflater} factory, and have therefore not * installed the default factory via {@link #installViewFactory()}. */ publicabstract View createView(@Nullable View parent, String name, @NonNull Context context, @NonNull AttributeSet attrs);
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 */ VectorEnabledTintResources.shouldBeUsed() /* Only tint wrap the context if enabled */ );