# PopupMenuCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/PopupMenuCompat.java+class:androidx.core.widget.PopupMenuCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class PopupMenuCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/widget/PopupMenu.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.OnTouchListener.html` | `https://developer.android.com/reference/androidx/core/widget/PopupMenuCompat#getDragToOpenListener(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html popupMenu)` Returns an `https://developer.android.com/reference/android/view/View.OnTouchListener.html` that can be added to the anchor view to implement drag-to-open behavior. |

## Public methods

### getDragToOpenListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @Nullable View.OnTouchListener getDragToOpenListener(@NonNull Object popupMenu)
```

Returns an `https://developer.android.com/reference/android/view/View.OnTouchListener.html` that can be added to the anchor view to implement drag-to-open behavior.

When the listener is set on a view, touching that view and dragging outside of its bounds will open the popup window. Lifting will select the currently touched list item.

Example usage:

```
PopupMenu myPopup = new PopupMenu(context, myAnchor);
myAnchor.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(myPopup));
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html popupMenu` | the PopupMenu against which to invoke the method |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/View.OnTouchListener.html` | a touch listener that controls drag-to-open behavior, or `null` on unsupported APIs |