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>";
}
? ? ? ? 网页加载可选择原生的webview。
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.问题
? ? ? ? 预览pdf、word等文档类型。需要先下载下来再预览。
? ? ? ? 打开前本着以防万一的心态再检查一遍内核是否初始化成功。失败也有失败的打开方式
????????
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);
}
|