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 */
);
}
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