Android website content not available

I have a webView. WebView shows html with text, images, buttons, etc.
I want to do a few things.

1) The user cannot select text in webView

2) The same behavior of clicking and long pressing a button.

I did the following things to solve my problems: First of all, I added the html page style:

body {
     ...
     -webkit-user-select: none;
     -webkit-touch-callout: none;
     ...
}

But that did not help me. This solution does not work on all androids.
So I tried to add a touch listener to the webView.

Listener Code:

webView.setOnTouchListener(new OnTouchListener() {

    private float prevX;
    private float prevY;

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        boolean handled = true;
        if (MotionEvent.ACTION_DOWN == event.getAction()) {
            prevX = event.getX();
            prevY = event.getY();
        } else if (MotionEvent.ACTION_UP == event.getAction()) {
            if (Math.abs(event.getX() - prevX) < 50
                    && Math.abs(event.getY() - prevY) < 50) {
                handled = (event.getEventTime() - event
                        .getDownTime()) > 200;
            }
        }

        Log.d("-------------------------------------------------", ""+handled);

        return handled;
    }

});

But that didn't work either, maybe I did something wrong? After that, I tried to add a listener with long clicks:

webView.setOnLongClickListener(new OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        v.performClick();
        return true;
    }
});

This solution solves only the first problem.

So where did I go wrong?

+5
1

addJavascriptInterface(); WebView. Activity. - Android Jscript. Jscript.

0

All Articles