Window与PhoneWindow入门

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值