My app uses one Activity to host several fragments. Each time one fragment is shown on the phone screen.The view of each fragment consists of several image icons.
Currently, user is able to press on two icons simultaneously with two fingers (with each fingure press on one icon). I want to disable this multi-touch feature on my app to allow only one icon press take effect at a time.
I tried the following ways:
Way 1: in my app theme, I added:
<item name="android:windowEnableSplitTouch">false</item>
Way 2: In Android Manifest xml, I added:
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
Way 3: in my Activity:
@Override public boolean onTouchEvent(MotionEvent event) { if(event.getPointerCount() > 1) { System.out.println("Multitouch detected!"); return true; } else return super.onTouchEvent(event); }
Unfortunately, none of my solutions work. So, How can I disable multi-touch feature in my app??
To prevent multi touch you should turn off splitMotionEvents or windowEnableSplitTouch attribute inside ViewGroup were buttons are located.
Introducing multi-touch That's called a "tap" gesture. Another gesture is called "drag". That's where you hold one finger on the screen and move it around, causing the content under your finger to scroll. Tap, drag, and a few other single-fingered gestures have always been supported in Android.
A multi-touch gesture is when multiple pointers (fingers) touch the screen at the same time. This lesson describes how to detect gestures that involve multiple pointers.
Enable or Disable MultiFinger Gestures for Synaptics Touchpad in Touchpad Settings 1 Open Settings, and click/tap on the Devices icon. 2 Click/tap on Touchpad on the left side, and click/tap on the Additional settings link under Related settings on the right side. (see screenshot below)
1 Open Settings, and click/tap on the Devices icon. 2 Click/tap on Touchpad on the left side, select the Swipes and Taps action you want in the drop menus of your available gestures (ex: "Three-finger gestures" and "Four-finger gestures"). (see screenshots below) Selecting Nothing for a gesture will disable it.
I only called it touch by finger in an attempt to help avoid confusion since it doesn't affect the touchpad or stylus pen. I was worried that stating disable touch might get taken as all forms of touch.
1 Open Settings, and click/tap on the Devices icon. 1 Open Settings, and click/tap on the Devices icon. The Two-Finger scrolling feature allows you to scroll vertically or horizontally from anywhere on the TouchPad surface.
For case: you have multiple buttons and you want make selected only one button. In parent (NOT ROOT, just parent of child) of buttons, in its xml params add
android:splitMotionEvents="false"
And that's it. Example:
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:splitMotionEvents="false" <-----------!!! > <Button android:id="@+id/button_main_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button1" /> <Button android:id="@+id/button_main_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button2" /> <Button android:id="@+id/button_main_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button3" /> </LinearLayout>
Btw. When you have 2 linearlayout with 3 buttons per layout, you should set this splitMotionEvents in that two layouts and also in parent of that 2 linearLayouts. Otherwise you will be able click only one button per layout (sum = 2 then). I hope you get it. :)
None of the other solutions didn't work for me or was too lame.
Yes I also faced this issue once and I found solution that android:splitMotionEvents="false" this will work only to direct children of a layout.
Example:
Like if you create two layout A and B and In A you have two buttons b1,b2 In B you have two buttons b3,b4
both A and B are in Parent Layout So first you have to clear that these buttons are not direct children of Parent Layout
In Parent Layout only have two children A and B
Than if you add android:splitMotionEvents="false" to Parent Layout then multi touch will not work on Layout A and Layout B but it will work on every button b1,b2,b3,b4 because these are not direct children of Parent Layout
So , If you want that multi touch will not work on these buttons also Than you have to add android:splitMotionEvents="false" this to every layout separately
There are some cases :
1).If you only add android:splitMotionEvents="false" on Layout A than you can not touch button b1 and button b2 at same time but you can touch button b1 or b2 and button b3 or b4 at same time.
2). just opposite of case 1.
3). But if you add android:splitMotionEvents="false" on both layouts than you can not touch any two buttons on your screen at same time.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:splitMotionEvents="false" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:splitMotionEvents="false" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="b1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="b2" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:splitMotionEvents="false" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="b3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="b4" /> </LinearLayout>
I think it might helpful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With