javaandroidpopupoverflow-menustylus-pen

S-Pen forces menu list to jump back to the top


The S-Pen does not scroll properly with a MenuDropDownListView after being created when pressing an OverflowMenuButton on the Toolbar (see gif below).

The menu is forced back to the top when the S-Pen makes contact.

This issue does not seem to be unique to a MenuDropDownListView. This also happens when scrolling a PopupMenu from the AndroidX library (androidx.appcompat.widget.PopupMenu). This behaviour, however, works as expected when using the standard Android library (android.widget.PopupMenu). The PopupMenu scenario is less vital to the issue I have but it may be related nevertheless.

The following gif is an example of attempting to scroll to the bottom of the list with an S-Pen, recorded on a Samsung Galaxy Note20 (Android 11, stock ROM):

Scroll OverflowMenu not working with S-Pen

The following gifs are an attempt at scrolling to the bottom of each PopupMenu, recorded on Samsung Galaxy Note20 (Android 11, stock ROM):

Android PopupMenu Scrolling Behaviour (working)

AndroidX PopupMenu Scrolling Behaviour (not working)

The code for the OverflowMenu is the following:

res/menu/example_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
>
    <item android:id="@+id/item1"
          android:icon="@drawable/ic_5g"
          android:title="Item 1"
          app:showAsAction="ifRoom"
    />

    <item android:id="@+id/item2"
          android:title="Item 1"
          app:showAsAction="never"
    />

    <item android:id="@+id/item3"
          android:title="Item 3"
          app:showAsAction="never">
        <menu>
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="TOP ITEMS HERE" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />
            <item android:title="Sub Item" />

             <!--  REPEATING...  -->

        </menu>
    </item>


</menu>

MainActivity.java

package com.example.popupmenutest;

import android.view.Menu;
import android.view.MenuInflater;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.example_menu, menu);
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Solution

  • Same behaviour if using a real USB mouse on my Galaxy Note 20 Ultra (Android 12), so I suppose it's a bug caused while using a Pointer (mouse or stylus it's the same while Hovering items).

    It could be caused by Samsung implementation or by androidx library, but it's hard to say which of them.....and I think it's unsolvable from our side.