Android 拾遗
16lz
2021-01-23
1. Activity的setContentView(int)方法,其实是这样的:
publicvoidsetContentView(intlayoutResID) {
getWindow().setContentView(layoutResID);
initActionBar();}
getWindow()方法是返回自PolicyManager.makeNewWindow()方法
“mWindow = PolicyManager.makeNewWindow(this)”
这样获取的一个Window对象,由于Window是个抽象类,唯一的基础是PhoneWindow,所以查找到PhoneWindow的setContentView(int)方法:
publicvoidsetContentView(intlayoutResID) {if ( mContentParent == null) {
installDecor();
} else {
mContentParent. removeAllViews();
}
mLayoutInflater.inflate(layoutResID, mContentParent);final Callback cb = getCallback();
if ( cb != null && ! isDestroyed()) {
cb. onContentChanged();
}
}
所以最后Activity中还是调用了LayoutInflater.inflate()方法。
更多相关文章
- Android NDK: Aborting出现NDK_PROJECT_PATH=null解决方法
- Android中用Toast.cancel()方法优化toast内容的显示
- 【从头学android】第二个程序同一个Activity中,切换布局时监听器
- JS或TS调用原生Android的方法
- 安装Android studio出现'tools.jar' seems to be not in Android
- Android 屏幕旋转后防止重新执行onCreate的方法。
- 【Android】‘activity supporting action_view is not set as b
- Android中完全退出程序的四种方法