Skip to content

Most visited

Recently visited

navigation

PopupWindow

public class PopupWindow
extends Object

java.lang.Object
   ↳ android.widget.PopupWindow


This class represents a popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.

Animation

On all versions of Android, popup window enter and exit animations may be specified by calling setAnimationStyle(int) and passing the resource ID for an animation style that defines windowEnterAnimation and windowExitAnimation. For example, passing Animation_Dialog will give a scale and alpha animation.
A window animation style may also be specified in the popup window's style XML via the popupAnimationStyle attribute.

Starting with API 23, more complex popup window enter and exit transitions may be specified by calling either setEnterTransition(Transition) or setExitTransition(Transition) and passing a Transition.
Popup enter and exit transitions may also be specified in the popup window's style XML via the popupEnterTransition and popupExitTransition attributes, respectively.

See also:

Summary

Nested classes

interface PopupWindow.OnDismissListener

Listener that is called when this popup window is dismissed. 

XML attributes

android:overlapAnchor Whether the popup window should overlap its anchor view. 
android:popupAnimationStyle The animation style to use for the popup window. 
android:popupBackground The background to use for the popup window. 
android:popupElevation Window elevation to use for the popup window. 
android:popupEnterTransition Transition used to move views into the popup window. 
android:popupExitTransition Transition used to move views out of the popup window. 

Constants

int INPUT_METHOD_FROM_FOCUSABLE

Mode for setInputMethodMode(int): the requirements for the input method should be based on the focusability of the popup.

int INPUT_METHOD_NEEDED

Mode for setInputMethodMode(int): this popup always needs to work with an input method, regardless of whether it is focusable.

int INPUT_METHOD_NOT_NEEDED

Mode for setInputMethodMode(int): this popup never needs to work with an input method, regardless of whether it is focusable.

Public constructors

PopupWindow(Context context)

Create a new empty, non focusable popup window of dimension (0,0).

PopupWindow(Context context, AttributeSet attrs)

Create a new empty, non focusable popup window of dimension (0,0).

PopupWindow(Context context, AttributeSet attrs, int defStyleAttr)

Create a new empty, non focusable popup window of dimension (0,0).

PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Create a new, empty, non focusable popup window of dimension (0,0).

PopupWindow()

Create a new empty, non focusable popup window of dimension (0,0).

PopupWindow(View contentView)

Create a new non focusable popup window which can display the contentView.

PopupWindow(int width, int height)

Create a new empty, non focusable popup window.

PopupWindow(View contentView, int width, int height)

Create a new non focusable popup window which can display the contentView.

PopupWindow(View contentView, int width, int height, boolean focusable)

Create a new popup window which can display the contentView.

Public methods

void dismiss()

Disposes of the popup window.

int getAnimationStyle()

Return the animation style to use the popup appears and disappears

Drawable getBackground()

Return the drawable used as the popup window's background.

View getContentView()

Return the view used as the content of the popup window.

float getElevation()
Transition getEnterTransition()

Returns the enter transition to be used when the popup window is shown.

Transition getExitTransition()

Returns the exit transition to be used when the popup window is dismissed.

int getHeight()

Returns the popup's requested height.

int getInputMethodMode()

Return the current value in setInputMethodMode(int).

int getMaxAvailableHeight(View anchor)

Returns the maximum height that is available for the popup to be completely shown.

int getMaxAvailableHeight(View anchor, int yOffset)

Returns the maximum height that is available for the popup to be completely shown.

int getMaxAvailableHeight(View anchor, int yOffset, boolean ignoreBottomDecorations)

Returns the maximum height that is available for the popup to be completely shown, optionally ignoring any bottom decorations such as the input method.

boolean getOverlapAnchor()

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

int getSoftInputMode()

Returns the current value in setSoftInputMode(int).

int getWidth()

Returns the popup's requested width.

int getWindowLayoutType()

Returns the layout type for this window.

boolean isAboveAnchor()

Indicates whether the popup is showing above (the y coordinate of the popup's bottom is less than the y coordinate of the anchor) or below the anchor view (the y coordinate of the popup is greater than y coordinate of the anchor's bottom).

boolean isAttachedInDecor()

Indicates whether the popup window will be attached in the decor frame of its parent window.

boolean isClippingEnabled()

Indicates whether clipping of the popup window is enabled.

boolean isFocusable()

Indicate whether the popup window can grab the focus.

boolean isOutsideTouchable()

Indicates whether the popup window will be informed of touch events outside of its window.

boolean isShowing()

Indicate whether this popup window is showing on screen.

boolean isSplitTouchEnabled()

Indicates whether the popup window supports splitting touches.

boolean isTouchable()

Indicates whether the popup window receives touch events.

void setAnimationStyle(int animationStyle)

Change the animation style resource for this popup.

void setAttachedInDecor(boolean enabled)

This will attach the popup window to the decor frame of the parent window to avoid overlaping with screen decorations like the navigation bar.

void setBackgroundDrawable(Drawable background)

Specifies the background drawable for this popup window.

void setClippingEnabled(boolean enabled)

Allows the popup window to extend beyond the bounds of the screen.

void setContentView(View contentView)

Change the popup's content.

void setElevation(float elevation)

Specifies the elevation for this popup window.

void setEnterTransition(Transition enterTransition)

Sets the enter transition to be used when the popup window is shown.

void setExitTransition(Transition exitTransition)

Sets the exit transition to be used when the popup window is dismissed.

void setFocusable(boolean focusable)

Changes the focusability of the popup window.

void setHeight(int height)

Sets the popup's requested height.

void setIgnoreCheekPress()

Set the flag on popup to ignore cheek press events; by default this flag is set to false which means the popup will not ignore cheek press dispatch events.

void setInputMethodMode(int mode)

Control how the popup operates with an input method: one of INPUT_METHOD_FROM_FOCUSABLE, INPUT_METHOD_NEEDED, or INPUT_METHOD_NOT_NEEDED.

void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener)

Sets the listener to be called when the window is dismissed.

void setOutsideTouchable(boolean touchable)

Controls whether the pop-up will be informed of touch events outside of its window.

void setOverlapAnchor(boolean overlapAnchor)

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

void setSoftInputMode(int mode)

Sets the operating mode for the soft input area.

void setSplitTouchEnabled(boolean enabled)

Allows the popup window to split touches across other windows that also support split touch.

void setTouchInterceptor(View.OnTouchListener l)

Set a callback for all touch events being dispatched to the popup window.

void setTouchable(boolean touchable)

Changes the touchability of the popup window.

void setWidth(int width)

Sets the popup's requested width.

void setWindowLayoutMode(int widthSpec, int heightSpec)

This method was deprecated in API level 23. Use setWidth(int) and setHeight(int).

void setWindowLayoutType(int layoutType)

Set the layout type for this window.

void showAsDropDown(View anchor)

Display the content view in a popup window anchored to the bottom-left corner of the anchor view.

void showAsDropDown(View anchor, int xoff, int yoff, int gravity)

Displays the content view in a popup window anchored to the corner of another view.

void showAsDropDown(View anchor, int xoff, int yoff)

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.

void showAtLocation(View parent, int gravity, int x, int y)

Display the content view in a popup window at the specified location.

void update(View anchor, int width, int height)

Updates the position and the dimension of the popup window.

void update(View anchor, int xoff, int yoff, int width, int height)

Updates the position and the dimension of the popup window.

void update(int width, int height)

Updates the dimension of the popup window.

void update()

Updates the state of the popup window, if it is currently being displayed, from the currently set state.

void update(int x, int y, int width, int height, boolean force)

Updates the position and the dimension of the popup window.

void update(int x, int y, int width, int height)

Updates the position and the dimension of the popup window.

Inherited methods

From class java.lang.Object

XML attributes

android:overlapAnchor

Whether the popup window should overlap its anchor view.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol overlapAnchor.

android:popupAnimationStyle

The animation style to use for the popup window.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol popupAnimationStyle.

android:popupBackground

The background to use for the popup window.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol popupBackground.

Related methods:

android:popupElevation

Window elevation to use for the popup window.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol popupElevation.

Related methods:

android:popupEnterTransition

Transition used to move views into the popup window.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol popupEnterTransition.

Related methods:

android:popupExitTransition

Transition used to move views out of the popup window.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol popupExitTransition.

Related methods:

Constants

INPUT_METHOD_FROM_FOCUSABLE

Added in API level 3
int INPUT_METHOD_FROM_FOCUSABLE

Mode for setInputMethodMode(int): the requirements for the input method should be based on the focusability of the popup. That is if it is focusable than it needs to work with the input method, else it doesn't.

Constant Value: 0 (0x00000000)

INPUT_METHOD_NEEDED

Added in API level 3
int INPUT_METHOD_NEEDED

Mode for setInputMethodMode(int): this popup always needs to work with an input method, regardless of whether it is focusable. This means that it will always be displayed so that the user can also operate the input method while it is shown.

Constant Value: 1 (0x00000001)

INPUT_METHOD_NOT_NEEDED

Added in API level 3
int INPUT_METHOD_NOT_NEEDED

Mode for setInputMethodMode(int): this popup never needs to work with an input method, regardless of whether it is focusable. This means that it will always be displayed to use as much space on the screen as needed, regardless of whether this covers the input method.

Constant Value: 2 (0x00000002)

Public constructors

PopupWindow

Added in API level 1
PopupWindow (Context context)

Create a new empty, non focusable popup window of dimension (0,0).

The popup does provide a background.

Parameters
context Context

PopupWindow

Added in API level 1
PopupWindow (Context context, 
                AttributeSet attrs)

Create a new empty, non focusable popup window of dimension (0,0).

The popup does provide a background.

Parameters
context Context
attrs AttributeSet

PopupWindow

Added in API level 1
PopupWindow (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Create a new empty, non focusable popup window of dimension (0,0).

The popup does provide a background.

Parameters
context Context
attrs AttributeSet
defStyleAttr int

PopupWindow

Added in API level 11
PopupWindow (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Create a new, empty, non focusable popup window of dimension (0,0).

The popup does not provide a background.

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

PopupWindow

Added in API level 1
PopupWindow ()

Create a new empty, non focusable popup window of dimension (0,0).

The popup does not provide any background. This should be handled by the content view.

PopupWindow

Added in API level 1
PopupWindow (View contentView)

Create a new non focusable popup window which can display the contentView. The dimension of the window are (0,0).

The popup does not provide any background. This should be handled by the content view.

Parameters
contentView View: the popup's content

PopupWindow

Added in API level 1
PopupWindow (int width, 
                int height)

Create a new empty, non focusable popup window. The dimension of the window must be passed to this constructor.

The popup does not provide any background. This should be handled by the content view.

Parameters
width int: the popup's width
height int: the popup's height

PopupWindow

Added in API level 1
PopupWindow (View contentView, 
                int width, 
                int height)

Create a new non focusable popup window which can display the contentView. The dimension of the window must be passed to this constructor.

The popup does not provide any background. This should be handled by the content view.

Parameters
contentView View: the popup's content
width int: the popup's width
height int: the popup's height

PopupWindow

Added in API level 1
PopupWindow (View contentView, 
                int width, 
                int height, 
                boolean focusable)

Create a new popup window which can display the contentView. The dimension of the window must be passed to this constructor.

The popup does not provide any background. This should be handled by the content view.

Parameters
contentView View: the popup's content
width int: the popup's width
height int: the popup's height
focusable boolean: true if the popup can be focused, false otherwise

Public methods

dismiss

Added in API level 1
void dismiss ()

Disposes of the popup window. This method can be invoked only after showAsDropDown(android.view.View) has been executed. Failing that, calling this method will have no effect.

See also:

getAnimationStyle

Added in API level 1
int getAnimationStyle ()

Return the animation style to use the popup appears and disappears

Returns
int the animation style to use the popup appears and disappears

getBackground

Added in API level 1
Drawable getBackground ()

Return the drawable used as the popup window's background.

Related XML Attributes:

Returns
Drawable the background drawable or null if not set

See also:

getContentView

Added in API level 1
View getContentView ()

Return the view used as the content of the popup window.

Returns
View a View representing the popup's content

See also:

getElevation

Added in API level 21
float getElevation ()

Related XML Attributes:

Returns
float the elevation for this popup window in pixels

See also:

getEnterTransition

Added in API level 24
Transition getEnterTransition ()

Returns the enter transition to be used when the popup window is shown.

Related XML Attributes:

Returns
Transition the enter transition, or null if not set

See also:

getExitTransition

Added in API level 24
Transition getExitTransition ()

Returns the exit transition to be used when the popup window is dismissed.

Related XML Attributes:

Returns
Transition the exit transition, or null if not set

See also:

getHeight

Added in API level 1
int getHeight ()

Returns the popup's requested height. May be a layout constant such as WRAP_CONTENT or MATCH_PARENT.

The actual size of the popup may depend on other factors such as clipping and window layout.

Returns
int the popup height in pixels or a layout constant

See also:

getInputMethodMode

Added in API level 3
int getInputMethodMode ()

Return the current value in setInputMethodMode(int).

Returns
int

See also:

getMaxAvailableHeight

Added in API level 1
int getMaxAvailableHeight (View anchor)

Returns the maximum height that is available for the popup to be completely shown. It is recommended that this height be the maximum for the popup's height, otherwise it is possible that the popup will be clipped.

Parameters
anchor View: The view on which the popup window must be anchored.
Returns
int The maximum available height for the popup to be completely shown.

getMaxAvailableHeight

Added in API level 3
int getMaxAvailableHeight (View anchor, 
                int yOffset)

Returns the maximum height that is available for the popup to be completely shown. It is recommended that this height be the maximum for the popup's height, otherwise it is possible that the popup will be clipped.

Parameters
anchor View: The view on which the popup window must be anchored.
yOffset int: y offset from the view's bottom edge
Returns
int The maximum available height for the popup to be completely shown.

getMaxAvailableHeight

Added in API level 24
int getMaxAvailableHeight (View anchor, 
                int yOffset, 
                boolean ignoreBottomDecorations)

Returns the maximum height that is available for the popup to be completely shown, optionally ignoring any bottom decorations such as the input method. It is recommended that this height be the maximum for the popup's height, otherwise it is possible that the popup will be clipped.

Parameters
anchor View: The view on which the popup window must be anchored.
yOffset int: y offset from the view's bottom edge
ignoreBottomDecorations boolean: if true, the height returned will be all the way to the bottom of the display, ignoring any bottom decorations
Returns
int The maximum available height for the popup to be completely shown.

getOverlapAnchor

Added in API level 23
boolean getOverlapAnchor ()

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

Returns
boolean Whether the popup should overlap its anchor.

See also:

getSoftInputMode

Added in API level 4
int getSoftInputMode ()

Returns the current value in setSoftInputMode(int).

Returns
int

See also:

getWidth

Added in API level 1
int getWidth ()

Returns the popup's requested width. May be a layout constant such as WRAP_CONTENT or MATCH_PARENT.

The actual size of the popup may depend on other factors such as clipping and window layout.

Returns
int the popup width in pixels or a layout constant

See also:

getWindowLayoutType

Added in API level 23
int getWindowLayoutType ()

Returns the layout type for this window.

Returns
int

See also:

isAboveAnchor

Added in API level 3
boolean isAboveAnchor ()

Indicates whether the popup is showing above (the y coordinate of the popup's bottom is less than the y coordinate of the anchor) or below the anchor view (the y coordinate of the popup is greater than y coordinate of the anchor's bottom). The value returned by this method is meaningful only after showAsDropDown(android.view.View) or showAsDropDown(android.view.View, int, int) was invoked.

Returns
boolean True if this popup is showing above the anchor view, false otherwise.

isAttachedInDecor

Added in API level 22
boolean isAttachedInDecor ()

Indicates whether the popup window will be attached in the decor frame of its parent window.

Returns
boolean true if the window will be attached to the decor frame of its parent window.

See also:

isClippingEnabled

Added in API level 3
boolean isClippingEnabled ()

Indicates whether clipping of the popup window is enabled.

Returns
boolean true if the clipping is enabled, false otherwise

See also:

isFocusable

Added in API level 1
boolean isFocusable ()

Indicate whether the popup window can grab the focus.

Returns
boolean true if the popup is focusable, false otherwise

See also:

isOutsideTouchable

Added in API level 3
boolean isOutsideTouchable ()

Indicates whether the popup window will be informed of touch events outside of its window.

Returns
boolean true if the popup is outside touchable, false otherwise

See also:

isShowing

Added in API level 1
boolean isShowing ()

Indicate whether this popup window is showing on screen.

Returns
boolean true if the popup is showing, false otherwise

isSplitTouchEnabled

Added in API level 11
boolean isSplitTouchEnabled ()

Indicates whether the popup window supports splitting touches.

Returns
boolean true if the touch splitting is enabled, false otherwise

See also:

isTouchable

Added in API level 3
boolean isTouchable ()

Indicates whether the popup window receives touch events.

Returns
boolean true if the popup is touchable, false otherwise

See also:

setAnimationStyle

Added in API level 1
void setAnimationStyle (int animationStyle)

Change the animation style resource for this popup.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
animationStyle int: animation style to use when the popup appears and disappears. Set to -1 for the default animation, 0 for no animation, or a resource identifier for an explicit animation.

See also:

setAttachedInDecor

Added in API level 22
void setAttachedInDecor (boolean enabled)

This will attach the popup window to the decor frame of the parent window to avoid overlaping with screen decorations like the navigation bar. Overrides the default behavior of the flag FLAG_LAYOUT_ATTACHED_IN_DECOR.

By default the flag is set on SDK version LOLLIPOP_MR1 or greater and cleared on lesser SDK versions.

Parameters
enabled boolean: true if the popup should be attached to the decor frame of its parent window.

See also:

setBackgroundDrawable

Added in API level 1
void setBackgroundDrawable (Drawable background)

Specifies the background drawable for this popup window. The background can be set to null.

Related XML Attributes:

Parameters
background Drawable: the popup's background

See also:

setClippingEnabled

Added in API level 3
void setClippingEnabled (boolean enabled)

Allows the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
enabled boolean: false if the window should be allowed to extend outside of the screen

See also:

setContentView

Added in API level 1
void setContentView (View contentView)

Change the popup's content. The content is represented by an instance of View.

This method has no effect if called when the popup is showing.

Parameters
contentView View: the new content for the popup

See also:

setElevation

Added in API level 21
void setElevation (float elevation)

Specifies the elevation for this popup window.

Related XML Attributes:

Parameters
elevation float: the popup's elevation in pixels

See also:

setEnterTransition

Added in API level 23
void setEnterTransition (Transition enterTransition)

Sets the enter transition to be used when the popup window is shown.

Related XML Attributes:

Parameters
enterTransition Transition: the enter transition, or null to clear

See also:

setExitTransition

Added in API level 23
void setExitTransition (Transition exitTransition)

Sets the exit transition to be used when the popup window is dismissed.

Related XML Attributes:

Parameters
exitTransition Transition: the exit transition, or null to clear

See also:

setFocusable

Added in API level 1
void setFocusable (boolean focusable)

Changes the focusability of the popup window. When focusable, the window will grab the focus from the current focused widget if the popup contains a focusable View. By default a popup window is not focusable.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
focusable boolean: true if the popup should grab focus, false otherwise.

See also:

setHeight

Added in API level 1
void setHeight (int height)

Sets the popup's requested height. May be a layout constant such as WRAP_CONTENT or MATCH_PARENT.

The actual size of the popup may depend on other factors such as clipping and window layout.

If the popup is showing, calling this method will take effect the next time the popup is shown.

Parameters
height int: the popup height in pixels or a layout constant

See also:

setIgnoreCheekPress

Added in API level 1
void setIgnoreCheekPress ()

Set the flag on popup to ignore cheek press events; by default this flag is set to false which means the popup will not ignore cheek press dispatch events.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

See also:

setInputMethodMode

Added in API level 3
void setInputMethodMode (int mode)

Control how the popup operates with an input method: one of INPUT_METHOD_FROM_FOCUSABLE, INPUT_METHOD_NEEDED, or INPUT_METHOD_NOT_NEEDED.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
mode int

See also:

setOnDismissListener

Added in API level 1
void setOnDismissListener (PopupWindow.OnDismissListener onDismissListener)

Sets the listener to be called when the window is dismissed.

Parameters
onDismissListener PopupWindow.OnDismissListener: The listener.

setOutsideTouchable

Added in API level 3
void setOutsideTouchable (boolean touchable)

Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable, which means touches outside of the window will be delivered to the window behind. The default is false.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
touchable boolean: true if the popup should receive outside touch events, false otherwise

See also:

setOverlapAnchor

Added in API level 23
void setOverlapAnchor (boolean overlapAnchor)

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

If the popup is showing, calling this method will take effect only the next time the popup is shown.

Parameters
overlapAnchor boolean: Whether the popup should overlap its anchor.

See also:

setSoftInputMode

Added in API level 4
void setSoftInputMode (int mode)

Sets the operating mode for the soft input area.

Parameters
mode int: The desired mode, see softInputMode for the full list

See also:

setSplitTouchEnabled

Added in API level 11
void setSplitTouchEnabled (boolean enabled)

Allows the popup window to split touches across other windows that also support split touch. When this flag is false, the first pointer that goes down determines the window to which all subsequent touches go until all pointers go up. When this flag is true, each pointer (not necessarily the first) that goes down determines the window to which all subsequent touches of that pointer will go until that pointer goes up thereby enabling touches with multiple pointers to be split across multiple windows.

Parameters
enabled boolean: true if the split touches should be enabled, false otherwise

See also:

setTouchInterceptor

Added in API level 3
void setTouchInterceptor (View.OnTouchListener l)

Set a callback for all touch events being dispatched to the popup window.

Parameters
l View.OnTouchListener

setTouchable

Added in API level 3
void setTouchable (boolean touchable)

Changes the touchability of the popup window. When touchable, the window will receive touch events, otherwise touch events will go to the window below it. By default the window is touchable.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

Parameters
touchable boolean: true if the popup should receive touch events, false otherwise

See also:

setWidth

Added in API level 1
void setWidth (int width)

Sets the popup's requested width. May be a layout constant such as WRAP_CONTENT or MATCH_PARENT.

The actual size of the popup may depend on other factors such as clipping and window layout.

If the popup is showing, calling this method will take effect the next time the popup is shown.

Parameters
width int: the popup width in pixels or a layout constant

See also:

setWindowLayoutMode

Added in API level 3
void setWindowLayoutMode (int widthSpec, 
                int heightSpec)

This method was deprecated in API level 23.
Use setWidth(int) and setHeight(int).

Change the width and height measure specs that are given to the window manager by the popup. By default these are 0, meaning that the current width or height is requested as an explicit size from the window manager. You can supply WRAP_CONTENT or MATCH_PARENT to have that measure spec supplied instead, replacing the absolute width and height that has been set in the popup.

If the popup is showing, calling this method will take effect only the next time the popup is shown.

Parameters
widthSpec int: an explicit width measure spec mode, either WRAP_CONTENT, MATCH_PARENT, or 0 to use the absolute width.
heightSpec int: an explicit height measure spec mode, either WRAP_CONTENT, MATCH_PARENT, or 0 to use the absolute height.

setWindowLayoutType

Added in API level 23
void setWindowLayoutType (int layoutType)

Set the layout type for this window.

See type for possible values.

Parameters
layoutType int: Layout type for this window.

See also:

showAsDropDown

Added in API level 1
void showAsDropDown (View anchor)

Display the content view in a popup window anchored to the bottom-left corner of the anchor view. 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.

Parameters
anchor View: the view on which to pin the popup window

See also:

showAsDropDown

Added in API level 19
void showAsDropDown (View anchor, 
                int xoff, 
                int yoff, 
                int gravity)

Displays the content view in a popup window anchored to the corner of another view. The window is positioned according to the specified gravity and 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 view can be scrolled, the specified vertical gravity will be ignored and the popup will anchor itself such that it is visible.

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

Parameters
anchor View: the view on which to pin the popup window
xoff int: A horizontal offset from the anchor in pixels
yoff int: A vertical offset from the anchor in pixels
gravity int: Alignment of the popup relative to the anchor

See also:

showAsDropDown

Added in API level 1
void showAsDropDown (View anchor, 
                int xoff, 
                int yoff)

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
anchor View: the view on which to pin the popup window
xoff int: A horizontal offset from the anchor in pixels
yoff int: A vertical offset from the anchor in pixels

See also:

showAtLocation

Added in API level 1
void showAtLocation (View parent, 
                int gravity, 
                int x, 
                int y)

Display the content view in a popup window at the specified location. If the popup window cannot fit on screen, it will be clipped. See WindowManager.LayoutParams for more information on how gravity and the x and y parameters are related. Specifying a gravity of NO_GRAVITY is similar to specifying Gravity.LEFT | Gravity.TOP.

Parameters
parent View: a parent view to get the getWindowToken() token from
gravity int: the gravity which controls the placement of the popup window
x int: the popup's x location offset
y int: the popup's y location offset

update

Added in API level 1
void update (View anchor, 
                int width, 
                int height)

Updates the position and the dimension of the popup window.

Calling this function also updates the window with the current popup state as described for update().

Parameters
anchor View: the popup's anchor view
width int: the new width in pixels, must be >= 0 or -1 to ignore
height int: the new height in pixels, must be >= 0 or -1 to ignore

update

Added in API level 1
void update (View anchor, 
                int xoff, 
                int yoff, 
                int width, 
                int height)

Updates the position and the dimension of the popup window.

Width and height can be set to -1 to update location only. Calling this function also updates the window with the current popup state as described for update().

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

Parameters
anchor View: the popup's anchor view
xoff int: x offset from the view's left edge
yoff int: y offset from the view's bottom edge
width int: the new width in pixels, must be >= 0 or -1 to ignore
height int: the new height in pixels, must be >= 0 or -1 to ignore

update

Added in API level 4
void update (int width, 
                int height)

Updates the dimension of the popup window.

Calling this function also updates the window with the current popup state as described for update().

Parameters
width int: the new width in pixels, must be >= 0 or -1 to ignore
height int: the new height in pixels, must be >= 0 or -1 to ignore

update

Added in API level 3
void update ()

Updates the state of the popup window, if it is currently being displayed, from the currently set state.

This includes:

update

Added in API level 3
void update (int x, 
                int y, 
                int width, 
                int height, 
                boolean force)

Updates the position and the dimension of the popup window.

Width and height can be set to -1 to update location only. Calling this function also updates the window with the current popup state as described for update().

Parameters
x int: the new x location
y int: the new y location
width int: the new width in pixels, must be >= 0 or -1 to ignore
height int: the new height in pixels, must be >= 0 or -1 to ignore
force boolean: true to reposition the window even if the specified position already seems to correspond to the LayoutParams, false to only reposition if needed

update

Added in API level 1
void update (int x, 
                int y, 
                int width, 
                int height)

Updates the position and the dimension of the popup window.

Width and height can be set to -1 to update location only. Calling this function also updates the window with the current popup state as described for update().

Parameters
x int: the new x location
y int: the new y location
width int: the new width in pixels, must be >= 0 or -1 to ignore
height int: the new height in pixels, must be >= 0 or -1 to ignore
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.