1. Activity的setContentView(int)方法,其实是这样的:
public void setContentView(intlayoutResID) {
getWindow().setContentView(layoutResID);
initActionBar();
}
getWindow()方法是返回自PolicyManager.makeNewWindow()方法
“mWindow = PolicyManager.makeNewWindow(this)”
这样获取的一个Window对象,由于Window是个抽象类,唯一的基础是PhoneWindow,所以查找到PhoneWindow的setContentView(int)方法:
public void setContentView(intlayoutResID) { if (mContentParent == null) { installDecor(); } else { mContentParent.removeAllViews(); } mLayoutInflater.inflate(layoutResID, mContentParent); finalCallbackcb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } }
所以最后Activity中还是调用了LayoutInflater.inflate()方法。