请教setContentView(int layoutResId)(android4.1.2)是怎么被调用的

henqiangda123 2014-03-04 05:25:31
请教问题如下:
android4.1.2查看Activity.setContentView()

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

public Window getWindow() {
return mWindow;
}

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) {

...//省略部分代码
mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this);
mWindow.getLayoutInflater().setPrivateFactory(this);


在PolicyManager.java中:

public static Window makeNewWindow(Context context) {
// this will likely crash somewhere beyond so we log it.
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"Call to PolicyManager.makeNewWindow is not supported", null);
return null;
}


[取自android4.1.2 sdk source]
(1)makeNewWindow返回了一个null值,mWindow=null,那么mWindow.setCallback(this)是怎么执行的呢?
(2)Activity的setContentView(int)方法在源码中是怎么实现的?跟源码跟丢了也找不到……

先谢过!
...全文
192 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
WelliJohn1991 2014-12-25
  • 打赏
  • 举报
回复
ponewwindow
henqiangda123 2014-03-06
  • 打赏
  • 举报
回复
还要再顶……
henqiangda123 2014-03-06
  • 打赏
  • 举报
回复
自己顶一次,还是没解决……
henqiangda123 2014-03-04
  • 打赏
  • 举报
回复
引用 3 楼 u012535657 的回复:
追踪到class文件中去看,发现只有一个抽象方法,对于它最终是如何实现的,我也不知道了(不好意思啦)。不过,在android中,有很多这种类似的封装好了的方法,这其实是android开发机制的体现,你只要弄清楚是实现什么功能、并遵循这样的规则进行开发就好了,真正要去弄懂最终如何实现,比较难诶
getWindow()返回的mWindow静态类型是Window,Window是抽象类,setContentWindow()的确是抽象方法,但是mWindow的实际类型必是一个继承了Window实现了setContentView()方法的Window子类型,我的问题其实就是mWindow的实际类型是什么?这个类中的setContentView()方法是如何实现的。
marlenna 2014-03-04
  • 打赏
  • 举报
回复
追踪到class文件中去看,发现只有一个抽象方法,对于它最终是如何实现的,我也不知道了(不好意思啦)。不过,在android中,有很多这种类似的封装好了的方法,这其实是android开发机制的体现,你只要弄清楚是实现什么功能、并遵循这样的规则进行开发就好了,真正要去弄懂最终如何实现,比较难诶
henqiangda123 2014-03-04
  • 打赏
  • 举报
回复
引用 1 楼 u012535657 的回复:
贴源码如下: /** * Set the activity content from a layout resource. The resource will be * inflated, adding all top-level views to the activity. * * @param layoutResID Resource ID to be inflated. * * @see #setContentView(android.view.View) * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) */ public void setContentView(int layoutResID) { getWindow().setContentView(layoutResID); initActionBar(); }
谢过,我的意思是跟踪源码的调用,setContentView最终是如何实现的?
marlenna 2014-03-04
  • 打赏
  • 举报
回复
贴源码如下: /** * Set the activity content from a layout resource. The resource will be * inflated, adding all top-level views to the activity. * * @param layoutResID Resource ID to be inflated. * * @see #setContentView(android.view.View) * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) */ public void setContentView(int layoutResID) { getWindow().setContentView(layoutResID); initActionBar(); }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧