webview
*public class Fragment01 extends Fragment {
private Button button;
private WebView webView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment01, container, false);
webView = view.findViewById(R.id.webview);
button = view.findViewById(R.id.diao);
webView.loadUrl("http://blog.zhaoliang5156.cn/zixunnew/calculator/index.html");
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(new Android(), "android");
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
webView.loadUrl("javascript:welcome(\"黎怡志\")");
}
});
return view;
}
}