1.问题:
x5内核初始化 报110,或者加载失败需要第二次进入才成功。
解决方案:
初始化位置建议不要放在application 放在首页activity。
2.问题:
scrollview嵌套后webview的高度不可控。留有大片空白。
解决方案:
(官方不建议scrollview嵌套webview 最好让webview自身滚动)
富文本加载可直接改变富文本将想加入的内容加入 减少层级 从而不使用scrollview
富文本最好带有<html>标签 没有可以代码加入
private String getHtmlData(String bodyHTML) {
String head = "<head>" +
"<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> " +
"<style>img{max-width: 100%; width:auto; height:auto;}" +
"video{max-width: 100%; width:auto; height:auto;}</style>" +
"</head>";
return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}
3.问题
webview视频播放 使用x5内核的好处就是自带封面处理。全屏切换。
contentWeb.setWebChromeClient(new WebChromeClient() {
@Override
public View getVideoLoadingProgressView() {
FrameLayout frameLayout = new FrameLayout(StudyContentActivity.this);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
return frameLayout;
}
@Override
public void onShowCustomView(View view, IX5WebChromeClient.CustomViewCallback callback) {
showCustomView(view, callback);//播放时横屏幕
}
@Override
public void onHideCustomView() {
hideCustomView();//不播放时竖屏
}
});
}
private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback callback) {
if (customView != null) {
callback.onCustomViewHidden();
return;
}
StudyContentActivity.this.getWindow().getDecorView();
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
fullscreenContainer = new FullscreenHolder(StudyContentActivity.this);
fullscreenContainer.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
decor.addView(fullscreenContainer, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
customView = view;
setStatusBarVisibility(false);
customViewCallback = callback;
customView.setVisibility(View.VISIBLE);
decor.setVisibility(View.VISIBLE);
decor.bringToFront();
}
/**
* 隐藏视频全屏
*/
private void hideCustomView() {
if (customView == null) {
return;
}
setStatusBarVisibility(true);
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
decor.removeView(fullscreenContainer);
fullscreenContainer = null;
customView = null;
customViewCallback.onCustomViewHidden();
contentWeb.setVisibility(View.VISIBLE);
}
/**
* 全屏容器界面
*/
static class FullscreenHolder extends FrameLayout {
public FullscreenHolder(Context ctx) {
super(ctx);
setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
return true;
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
/** 回退键 事件处理 优先级:视频播放全屏-网页回退-关闭页面 */
if (customView != null) {
hideCustomView();
} else if (contentWeb.canGoBack()) {
contentWeb.goBack();
} else {
finish();
}
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
4.问题
打开前本着以防万一的心态再检查一遍内核是否初始化成功。失败也有失败的打开方式
if (x5WebViewExtension != null) {
Intent intent = new Intent(this, SourcesPreviewActivity.class);
intent.putExtra("info", stateBean.fileInfoBean);
startActivity(intent);
} else {
QbSdk.openFileReader(context, stateBean.fileInfoBean.getFile().getPath(), null, null);
}
sourcesPreviewActivity内动态添加TbsReaderView bsReaderTemp为预览的临时路径
bsReaderTemp = Environment.getExternalStorageDirectory() + "/TbsReaderTemp";
File bsReaderTempFile = new File(bsReaderTemp);
if (!bsReaderTempFile.exists()) {
boolean mkdir = bsReaderTempFile.mkdir();
if (!mkdir) {
}
}
Bundle localBundle = new Bundle();
localBundle.putString("filePath", fileInfoBean.getFile().getPath());
localBundle.putString("tempPath", bsReaderTemp);
if (this.mTbsReaderView == null) {
mTbsReaderView = new TbsReaderView(this, (integer, o, o1) -> {
});
contentCon.addView(mTbsReaderView, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT));
}
boolean bool = this.mTbsReaderView.preOpen(getFileType(fileInfoBean.getFile().getPath()), false);
if (bool) {
this.mTbsReaderView.openFile(localBundle);
} else {
QbSdk.clearAllWebViewCache(this, true);
}
原文地址:https://blog.csdn.net/weixin_40124103/article/details/126097579
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_28492.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。