网页标题整改

This commit is contained in:
18401019693
2022-09-21 16:28:00 +08:00
parent 362dff002f
commit f8826d0239
6 changed files with 86 additions and 20 deletions

View File

@@ -0,0 +1,12 @@
package com.yunbao.common.views.weight;
import android.app.Activity;
public class JavascriptInterface {
private Activity context;
public JavascriptInterface(Activity context) {
this.context = context;
}
}

View File

@@ -0,0 +1,38 @@
package com.yunbao.common.views.weight;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.AttributeSet;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* pdlive对H5页面开放的web控件
*/
public class PDLiveWebView extends WebView {
public PDLiveWebView(@NonNull Activity context) {
super(context);
init(context);
}
public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
private void init(Activity context) {
getSettings().setJavaScriptEnabled(true); // 是否开启JS支持
getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
getSettings().setDomStorageEnabled(true);
this.addJavascriptInterface(new JavascriptInterface(context), "androidObject");
}
}