Skip to content Skip to sidebar Skip to footer

Disabling Touch In Android (only Allowing Stylus)

I'm writing an Android 5.1 application for a tablet and I'm able to distinguish between touch and stylus input with the help of the MotionEvent object. Is it possible to only allow

Solution 1:

Not sure there's no better approach but you can create custom view, put it as top-most in your layout (make it take full width and height so it covers whole ares). The view only job would be to handle inputs and "consume" all motion events you want to filter out (ie these not coming from stylus) by marking them as processed, and ignore all the others, allowing framework to propagate thru your view hierarchy for regular handling by other views.

EDIT

The simplest implementation would be to make your view extend something existing, yet simple, like. FrameLayout or Space (so you do not need to bother all the measure stuff) and override onTouchEvent() to filter all the inputs. If this something you do not want to pass, "consume" it here by returning true, otherwise return false so it will propagate. And important to make your view top-most to overlay all the others, i.e.

FrameLayout
   YourCustomView
   PreviousLayout

Post a Comment for "Disabling Touch In Android (only Allowing Stylus)"