我正在尝试通过浏览器打开web site,但它拒绝用户输入
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
urlSite = bundle.getString("passed_url");
}
_toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(_toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
webView = (WebView) findViewById(R.id.webView);
//webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
WebSettings webSettings = webView.getSettings();
// enable javascript
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
//webSettings.setUseWideViewPort(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.equals("about:blank")) {
view.loadUrl(url);
}
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
if (urlSite != null) {
webView.clearCache(true);
webView.loadUrl(urlSite);
}
//webView.requestFocus(View.FOCUS_DOWN);
}
我的尝试我尝试了webView.requestFocus(View.FOCUS_DOWN),但它无法正常工作,我在下面尝试了两个代码段,但它们也无法解决我的问题。
我挣扎了很长时间,无法找到答案,有人可以帮助我吗?
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
v.requestFocusFromTouch();
break;
}
return false;
}
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
答案 0 :(得分:1)
只需添加以下行:
webSettings.setUseWideViewPort(true);