AppCompatActivity # findViewById
public <T extends View> T findViewById(@IdRes int id) {
return this.getDelegate().findViewById(id);
}
AppCompatActivity # getDelegate
@NonNull
public AppCompatDelegate getDelegate() {
if (this.mDelegate == null) {
this.mDelegate = AppCompatDelegate.create(this, this);
}
return this.mDelegate;
}
AppCompatDelegate # create
public static AppCompatDelegate create(Activity activity, AppCompatCallback callback) {
return new AppCompatDelegateImpl(activity, activity.getWindow(), callback);
}
AppCompatDelegateImpl # findViewById
@Nullable
public <T extends View> T findViewById(@IdRes int id) {
this.ensureSubDecor();
return this.mWindow.findViewById(id);
}
Window # findViewById
@Nullable
public <T extends View> T findViewById(@IdRes int id) {
return getDecorView().findViewById(id);
}
DecorView # findViewById(其实是调用父类View的方法)
@Nullable
public final <T extends View> T findViewById(@IdRes int id) {
if (id == NO_ID) {
return null;
}
return findViewTraversal(id);
}
View # findViewTraversal
protected <T extends View> T findViewTraversal(@IdRes int id) {
if (id == mID) {
return (T) this;
}
return null;
}