3

我想知道Activity.javasetContentView()方法到底在调用/做什么。

是 Android 源代码和第 1646 行的代码存根:

public void setContentView(int layoutResID) {
    getWindow().setContentView(layoutResID);
}

这是我的踪迹...

在第 642 行,我们知道它是类型android.view.Window

private Window mWindow;

但是Window.java是一个抽象类。在第 738 行,该方法也是抽象的:

public abstract void setContentView(int layoutResID);

实际的函数体在哪里实现?

回到Activity.java文件,在第 3746 行,我们发现了一些初始化mWindow

mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this);
...

好吧,关于com.android.internal.policy.PolicyManager's makeNewWindow()

public static Window makeNewWindow(Context context) {
    return sPolicy.makeNewWindow(context);
}

private static final IPolicy sPolicy;
Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);
sPolicy = (IPolicy)policyClass.newInstance();

IPolicy.java是一个接口,这意味着根本没有实现。

我的踪迹不能再进一步了。你能帮帮我吗?

特别是,我知道Activity.setContentView()最终会调用android.support.v4.app.Fragment.java's Fragment.onInflate()- 920 行,Fragment.onAttach()- 928 行,Fragment.onCreate()- 953 行,Fragment.onCreateView()- 967 行和Fragment.onViewCreated()- 991 行。

4

1 回答 1

0

你可以在这里找到这个来源

政策实施:来源

窗口实现:源码

于 2013-11-26T09:10:35.290 回答