0

I have a fullscreen WebView and I want to; If my user double tap the screen, prevent second tap.

I am very very new on Android, please be very clear. I pasted my codes;

MainActivity.java

public class MainActivity extends Activity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // REMOTE RESOURCE
         mWebView.loadUrl("https://www.example.com");
        mWebView.setWebViewClient(new MyWebViewClient());

    }

    // Prevent the back-button from closing the app
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

}

MyWebViewClient.java

public class MyWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().endsWith("www.example.com")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}
Meltem
  • 89
  • 1
  • 9
  • Check [this](https://stackoverflow.com/a/29142489/2196176). – Sunny Sep 01 '18 at 05:13
  • there is no point about my request and zoom. I don't care the zoom. Already, in my webpage when you double click it doesn't zoom. I want to prevent second tap. That's it – Meltem Sep 01 '18 at 07:08
  • @Meltem, I do not want to provide a half answer as I am not in a situation where I am able to provide a full answer... So I am hoping someone else can write up some code that does this, but if you want to prevent multiple clicks a simple way is to **timeout** a click using a **ClickListener** like what is shown in this article: https://thedeveloperworldisyours.com/android/to-avoid-multiple-button-click-at-same-time/ in this example, your **View** is not a button, but your **WebView** – ViaTech Sep 01 '18 at 09:15

0 Answers0