# PopupWindowCompat

# PopupWindowCompat

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/widget/PopupWindowCompat "View this page in Java")

<br />

```
class PopupWindowCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html).

## Summary

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [getOverlapAnchor](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#getOverlapAnchor(android.widget.PopupWindow))`(popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html)`)` Returns whether the popup window should overlap its anchor view when displayed as a drop-down.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [getWindowLayoutType](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#getWindowLayoutType(android.widget.PopupWindow))`(popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html)`)` Returns the layout type for this window.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setOverlapAnchor](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#setOverlapAnchor(android.widget.PopupWindow,boolean))`(popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html)`, overlapAnchor: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether the popup window should overlap its anchor view when displayed as a drop-down.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setWindowLayoutType](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#setWindowLayoutType(android.widget.PopupWindow,int))`(popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html)`, layoutType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Set the layout type for this window.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "popup.showAsDropDown(anchor, xoff, yoff, gravity)")` ~~[showAsDropDown](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#showAsDropDown(android.widget.PopupWindow,android.view.View,int,int,int))~~`(` ` popup: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html)`,` ` anchor: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` xoff: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` yoff: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` gravity: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` **This function is deprecated.** Call showAsDropDown directly. <br /> |

## Public functions

### getOverlapAnchor

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

```
java-static fun getOverlapAnchor(popupWindow: PopupWindow): Boolean
```

Returns whether the popup window should overlap its anchor view when displayed as a drop-down.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the popup should overlap its anchor. |

### getWindowLayoutType

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

```
java-static fun getWindowLayoutType(popupWindow: PopupWindow): Int
```

Returns the layout type for this window.  

|                                                                             See also                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setWindowLayoutType](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#setWindowLayoutType(android.widget.PopupWindow,int)) |   |

### setOverlapAnchor

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

```
java-static fun setOverlapAnchor(popupWindow: PopupWindow, overlapAnchor: Boolean): Unit
```

Sets whether the popup window should overlap its anchor view when displayed as a drop-down.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|----------------------------------------------|
| `popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html) | popup window for which to set the anchor.    |
| `overlapAnchor: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)  | Whether the popup should overlap its anchor. |

### setWindowLayoutType

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

```
java-static fun setWindowLayoutType(popupWindow: PopupWindow, layoutType: Int): Unit
```

Set the layout type for this window. This value will be passed through to[type](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#type())therefore the value should match any value[type](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#type())accepts.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|------------------------------------------------|
| `popupWindow: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html) | popup window for which to set the layout type. |
| `layoutType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)             | Layout type for this window.                   |

|                                              See also                                               |
|-----------------------------------------------------------------------------------------------------|---|
| [type](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#type()) |   |

### showAsDropDown

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

```
@ReplaceWith(expression = "popup.showAsDropDown(anchor, xoff, yoff, gravity)")
java-static fun [showAsDropDown](https://developer.android.com/reference/kotlin/androidx/core/widget/PopupWindowCompat#showAsDropDown(android.widget.PopupWindow,android.view.View,int,int,int))(
    popup: PopupWindow,
    anchor: View,
    xoff: Int,
    yoff: Int,
    gravity: Int
): Unit
```
| **This function is deprecated.**   
|
| Call showAsDropDown directly.

Display the content view in a popup window anchored to the bottom-left corner of the anchor view offset by the specified x and y coordinates. If there is not enough room on screen to show the popup in its entirety, this method tries to find a parent scroll view to scroll. If no parent scroll view can be scrolled, the bottom-left corner of the popup is pinned at the top left corner of the anchor view.

If the view later scrolls to move`anchor`to a different location, the popup will be moved correspondingly.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `popup: `[PopupWindow](https://developer.android.com/reference/android/widget/PopupWindow.html) | the PopupWindow to show                       |
| `anchor: `[View](https://developer.android.com/reference/android/view/View.html)                | the view on which to pin the popup window     |
| `xoff: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)             | A horizontal offset from the anchor in pixels |
| `yoff: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)             | A vertical offset from the anchor in pixels   |
| `gravity: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | Alignment of the popup relative to the anchor |