简体   繁体   中英

MIUI10 android textview setOnTouchListener ACTION_UP not called

I am confused about this strange problem. Normally, on many phones, this is not a problem. But I tried three MIUI10 phones with this problem, and other systems have not encountered it. Perhaps this is a MIUI10 system bug?

If you have a MIUI10 phone, please help test it.

And how can I solve this problem to be compatible with many devices? All help is welcome.

The code is as follows, very simple:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp"
        android:padding="15dp"
        android:background="#1ad9ca"
        android:textColor="#ffffff"
        android:text="Hold to talk" />

</RelativeLayout>

findViewById(R.id.text).setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "ACTION_UP");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "ACTION_CANCEL");
                break;
        }

        return true;
    }
});

And in my device, Hold TextView for a few seconds and raise my hand , ACTION_CANCEL is called, and ACTION_UP is not called . Here are the logs:

D/MainActivity: ACTION_DOWN
D/MainActivity: ACTION_MOVE
D/MainActivity: ACTION_MOVE
D/MainActivity: ACTION_CANCEL

And I want to do some logic in ACTION_UP case , not in ACTION_CANCEL case.

The test device info:

Phone name: Xiaomi 8
Android system version: Android 9
MIUI system version: MIUI 10.1.2.0

Verified on my miui phone, this problem occurs only on 10.2.xx version, when upgrading to 10.3.3.0, the problem no more occurs.

While dispatching ACTION_UP event, miui intercepts this event and changes action from ACTION_UP to ACTION_CANCEL, but nothing popup shows on screen, seems like a bug on 10.2.xx

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