不论点击还是标签链接都失效,反复查阅,可能性方法试了又试最终解决。总结下:
1、开启js支持
2、webview 设置WebChromeClient
3、websetting和webviewclient
“`
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView wv = new WebView(getApplicationContext());
WebSettings webSettings = wv.getSettings();
wv.getSettings().setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDefaultTextEncodingName(“utf-8”);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.requestFocus();
//点击超链接的时候重新在原来的进程上加载URL
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
【┈━═☆|android用webview加载H5页面出现点击事件失效的问题解决】// wv.loadUrl(“https://www.baidu.com“);
wv.loadUrl(“file:///android_asset/H5/test.html”);
setContentView(wv);
}
“`