简体   繁体   中英

How to disable touch event?

I have an Application, in one of myActivity i am using webView . With some type of tablets i have the problem of double touch. a touch event in My JS and other in Android. I can't remove the touch event in JS because with some tablets. i ought to implement it. So I would like to Stop the Android touch events for this Activity and it's child and not for all the application. I tried

public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = viewGroup.getChildAt(i);
        view.setEnabled(enabled);
        if (view instanceof ViewGroup) {
            enableDisableViewGroup((ViewGroup) view, enabled);
        }
    }
}

The way to ignore a touch event on a webview is quite simple, just do :

mWebView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false; //returns true if you wan't also ignore the js touch events
    }
});

The thing is, I'm not sure the triggered event are from the webview or another view, you need to define it so you can set this same OnTouchListener on the appropriate view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM