Window
基础
其子类为PhoneWindow。
构造方法
在Activity#attch()中,会执行new PhoneWindow(this),因此Window中的mContext成员变量为它所关联的Activity。当然,在Activity中可以通过mWindow指向一个PhoneWindow实例。
setWindowManager()
在Activity#attach()中调用,该方法会对mWindowManager变量进行赋值,其为一个WindowManagerImpl实例。
setCallback()
在Activity#attach()中调用,为mCallback赋值,其值与mContext一样,都是指向同一个Activity实例。
PhoneWindow
setContentView
调用Activity#setContentView()最终会调用到PhoneWindow#setContentView,先罗列里面会用到的方法。如下:
//可以看出它mDecor为DecorView对象
protected DecorView generateDecor() {
return new DecorView(getContext(), -1);
}
//findViewById()如下:
public View findViewById(@IdRes int id) {
return getDecorView().findViewById(id);
}
//获取theme中关于window属性的设置
public final TypedArray getWindowStyle() {
synchronized (this) {
if (mWindowStyle == null) {
mWindowStyle = mContext.obtainStyledAttributes(
com.android.internal.R.styleable.Window);
}
return mWindowStyle;
}
}
public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
return getTheme().obtainStyledAttributes(attrs);
}
//是否有指定的feature。
public boolean hasFeature(int feature) {
return (getFeatures() & (1 << feature)) != 0;
}
//设置feature。上面的getFeatures()只是返回mFeatures
public boole