在写一个Activity的时候,经常会先调用setContentView方法来设置Activity的布局,那么setContentView中究竟做了什么呢?
public void setContentView(@LayoutRes int layoutResID) {
getWindow().setContentView(layoutResID);
initWindowDecorActionBar();
}
Activity的getWindow()方法在之前,Activity的初始化的时候,就已经了解了,其是在Activity的attach方法中初始化的
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config, String referrer, IVoiceInteractor voiceInteractor) {
......
// 初始化PhoneWindow对象
mWindow = new PhoneWindow(this);
mWindow.setCallback(this);
mWindow.setOnWindowDismissedCallback(this);
mWindow.getLayoutInflater().setPrivateFactory(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
}
if (info.uiOptions != 0) {
mWindow.setUiOptions(info.uiOptions);
}
......
}
getWindow()方法中取得的mWindow就是PhoneWindow对象,那么Activity的setContentView首先调用了PhoneWindow中的setContentView方法
@Override
public vo