0

我在我的片段中添加了一个 webview。页面加载得很漂亮,我可以选择文本框,但是输入它们不起作用。我从这个链接中获取帮助。 为什么 Android WebView 拒绝用户输入?

但它也没有帮助我。我的代码是..

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();
        }

    }
}

}

4

1 回答 1

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;
    }
于 2013-10-02T08:19:39.577 回答