我在我的片段中添加了一个webview。页面加载很漂亮,我可以选择文本框,但输入它们将无法工作。我从这个链接中获取帮助.. Why is Android WebView refusing user input?
但它也没有帮助我。我的代码是......
public class CityTouchFinal extends Fragment{
View v;
private ProgressDialog pd;
static WebView webView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
v = inflater.inflate(R.layout.webload, null);
webView = (WebView) v.findViewById(R.id.load);
ConnectionDetector connectionDetector = new ConnectionDetector(
getActivity());
if (connectionDetector.isConnectingToInternet() == true)
{
pd = new ProgressDialog(getActivity());
pd = ProgressDialog.show(getActivity(), "Url", "loading");
pd.show();
}
else {
Toast.makeText(getActivity(), "Check Internet Connrction",
Toast.LENGTH_SHORT).show();
FragmentTabHost tabHost = Moctabactivty.self.mTabHost;
tabHost.setCurrentTab(0);
}
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webView.loadUrl("http://www.google.com");
/// webView.loadUrl("https://ibank.thecitybank.com/ilogin.php");
webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
webView.setFocusable(true);
webView.setClickable(true);
webView.setHapticFeedbackEnabled(true);
webView.setFocusableInTouchMode(true);
webView.requestFocus(View.FOCUS_DOWN);
webView.setWebViewClient(new MyWebViewClient());
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
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;
}
});
return v;
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (!pd.isShowing()) {
pd.show();
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
System.out.println("on finish");
if (pd.isShowing()) {
pd.dismiss();
}
}
}
}
答案 0 :(得分:0)
我找到了解决方案,我已将代码更改为..
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;
}