android-动态添加包含WebView的Fragment显示空白
来源:互联网 发布:吉威时代待遇知乎 编辑:程序博客网 时间:2024/06/05 13:27
点击按钮新增包含WebView的Fragment时,WebView显示空白,其中Fragment除了WebView外还有其他控件,当使用activity打开该Fragment,LogCat输出发现已经执行了:
@Overridepublic void onPageFinished(WebView view, String url)
但是WebView是空白的,点击Fragment的其中一个按钮后WebView的内容就显示了,此时觉得是该Fragment没有"获得焦点",修改新增Fragment方法:
getFragmentManager().beginTransaction().add(android.R.id.content,one,"qe").commit();原来我使用的不是android.R.id.content这个值,而是设置到自己定义的一个:
<LinearLayout android:id="@+id/my_content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:focusable="true" />
修改为:android.R.id.content就可以显示WebView内容。android.R.id.content是根视图,使得该Fragment获得“焦点”。
后来网上查了一下别人不是用LinearLayout,修改为:
<FrameLayout android:id="@+id/my_fragment" android:layout_width="fill_parent" android:layout_height="wrap_content"/>当新增一个有WebView的Fragment时,WebView显示出内容。
解决办法暂时有两种:
1、如下,使用android.R.id.content,代替你的布局,我的是LinearLayout,但是使用android.R.id.content,Fragment会覆盖原布局的内容,此内容不会清除。
getFragmentManager().beginTransaction().add(android.R.id.content,one,"qe").commit();
2、如下,使用FrameLayout代替LinearLayout,此时不会像android.R.id.content覆盖掉原布局的东西,而是根据FrameLayout所在layout进行布局
<FrameLayout android:id="@+id/my_fragment" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
暂时只是记录解决的方法,从以上两种解决方案看出,布局对于嵌入到Fragment的WebView的内容显示是有影响的,改天再查明是什么原因。
0 0
- android-动态添加包含WebView的Fragment显示空白
- Android:使用Slidingmenu显示WebView的时候出现空白部分
- Android webview 加载自签名的https网页显示空白
- WebView显示页面有空白边Android
- Android webview 加载https网页显示空白
- Android webview 加载https网页显示空白
- android webview显示网页空白问题
- Android webview 加载https网页显示空白
- Android 动态添加Fragment
- Android 动态添加Fragment
- Android 动态添加Fragment
- Fragment的动态添加
- android 7.0 使用 webview 访问 https 协议的网址,界面显示空白,其他android版本正常。
- Android主页动态添加Fragment
- android fragment动态显示隐藏
- Android WebView显示HTML时右边有空白
- Android WebView显示HTML时右边有空白
- Android 7.0系统webview 显示https页面空白处理
- fans-rt介绍(2)-系统功能介绍
- UNIX环境高级编程之----多线程同步学习
- Eclipse中Git的使用
- fans-rt 介绍(3)-可选组件(待实现)
- 论深造与就业的抉择
- android-动态添加包含WebView的Fragment显示空白
- fans-rt 介绍(4)-源码文件夹介绍
- 不可以!
- 关于矩形排样问题(三)
- Java实现的3D计算机图形类库与引擎
- 《架构之美》笔记
- 无法将网络更改为桥接状态:没有未桥接的主机网络适配器
- JAVA字符串的比较
- 红黑树的插入