Uncategorized

Pop up Window

32 min read administrator

Added inAPI level 1
Summary:Nested Classes|XML Attrs|Constants|Ctors|Methods|Inherited Methods

PopupWindow


Kotlin|Java

`
public

class
PopupWindow

extends [Object](https://developer.android.com/reference/java/lang/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 callingsetAnimationStyle(int)and passing the resource ID for an animation style that defineswindowEnterAnimationandwindowExitAnimation. For example, passingR.style.Animation_Dialogwill give a scale and alpha animation.
A window animation style may also be specified in the popup window’s style XML via thepopupAnimationStyleattribute.

Starting with API 23, more complex popup window enter and exit transitions may be specified by calling eithersetEnterTransition(android.transition.Transition)orsetExitTransition(android.transition.Transition)and passing aTransition.
Popup enter and exit transitions may also be specified in the popup window’s style XML via thepopupEnterTransitionandpopupExitTransitionattributes, respectively.

See also:

Summary

### Nested classes
interfacePopupWindow.OnDismissListener Listener that is called when this popup window is dismissed.
### XML attributes
android:overlapAnchorWhether the popup window should overlap its anchor view.
android:popupAnimationStyleThe animation style to use for the popup window.
android:popupBackgroundThe background to use for the popup window.
android:popupElevationWindow elevation to use for the popup window.
android:popupEnterTransitionTransition used to move views into the popup window.
android:popupExitTransitionTransition used to move views out of the popup window.
### Constants
intINPUT_METHOD_FROM_FOCUSABLE Mode forsetInputMethodMode(int): the requirements for the input method should be based on the focusability of the popup.
intINPUT_METHOD_NEEDED Mode forsetInputMethodMode(int): this popup always needs to work with an input method, regardless of whether it is focusable.
intINPUT_METHOD_NOT_NEEDED Mode forsetInputMethodMode(int): this popup never needs to work with an input method, regardless of whether it is focusable.
### Public constructors
PopupWindow()
Create a new empty, non focusable popup window of dimension (0,0).
PopupWindow(Contextcontext)
Create a new empty, non focusable popup window of dimension (0,0).
PopupWindow(Contextcontext,AttributeSetattrs)
Create a new empty, non focusable popup window of dimension (0,0).
PopupWindow(Contextcontext,AttributeSetattrs, int defStyleAttr)
Create a new empty, non focusable popup window of dimension (0,0).
PopupWindow(Contextcontext,AttributeSetattrs, int defStyleAttr, int defStyleRes)
Create a new, empty, non focusable popup window of dimension (0,0).
PopupWindow(ViewcontentView)
Create a new non focusable popup window which can display thecontentView.
PopupWindow(ViewcontentView, int width, int height)
Create a new non focusable popup window which can display thecontentView.
PopupWindow(ViewcontentView, int width, int height, boolean focusable)
Create a new popup window which can display thecontentView.
PopupWindow(int width, int height)
Create a new empty, non focusable popup window.
### Public methods
voiddismiss() Disposes of the popup window.
intgetAnimationStyle()
Return the animation style to use the popup appears and disappears
DrawablegetBackground() Return the drawable used as the popup window’s background.
ViewgetContentView()
Return the view used as the content of the popup window.
floatgetElevation()
TransitiongetEnterTransition() Returns the enter transition to be used when the popup window is shown.
RectgetEpicenterBounds()
Returns bounds which are used as a center of the enter and exit transitions.
TransitiongetExitTransition() Returns the exit transition to be used when the popup window is dismissed.
intgetHeight() Returns the popup’s requested height.
intgetInputMethodMode() Return the current value insetInputMethodMode(int).
intgetMaxAvailableHeight(Viewanchor) Returns the maximum height that is available for the popup to be completely shown.
intgetMaxAvailableHeight(Viewanchor, int yOffset) Returns the maximum height that is available for the popup to be completely shown.
intgetMaxAvailableHeight(Viewanchor, 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.
booleangetOverlapAnchor() Returns whether the popup window should overlap its anchor view when displayed as a drop-down.
intgetSoftInputMode() Returns the current value insetSoftInputMode(int).
intgetWidth() Returns the popup’s requested width.
intgetWindowLayoutType() Returns the layout type for this window.
booleanisAboveAnchor() 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).
booleanisAttachedInDecor()
Indicates whether the popup window will be attached in the decor frame of its parent window.
booleanisClippedToScreen()
Indicates whether this popup will be clipped to the screen and not to the containing window
booleanisClippingEnabled()
Indicates whether clipping of the popup window is enabled.
booleanisFocusable()
Indicate whether the popup window can grab the focus.
booleanisLaidOutInScreen()
Indicates whether the popup window will be forced into using absolute screen coordinates for positioning.
booleanisOutsideTouchable()
Indicates whether the popup window will be informed of touch events outside of its window.
booleanisShowing()
Indicate whether this popup window is showing on screen.
booleanisSplitTouchEnabled()
Indicates whether the popup window supports splitting touches.
booleanisTouchModal()
Indicates whether outside touches will be sent to this window or other windows behind it
booleanisTouchable()
Indicates whether the popup window receives touch events.
voidsetAnimationStyle(int animationStyle)
Change the animation style resource for this popup.
voidsetAttachedInDecor(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.
voidsetBackgroundDrawable(Drawablebackground) Specifies the background drawable for this popup window.
voidsetClippingEnabled(boolean enabled)
Allows the popup window to extend beyond the bounds of the screen.
voidsetContentView(ViewcontentView)
Change the popup’s content.
voidsetElevation(float elevation) Specifies the elevation for this popup window.
voidsetEnterTransition(TransitionenterTransition) Sets the enter transition to be used when the popup window is shown.
voidsetEpicenterBounds(Rectbounds)
Sets the bounds used as the epicenter of the enter and exit transitions.
voidsetExitTransition(TransitionexitTransition) Sets the exit transition to be used when the popup window is dismissed.
voidsetFocusable(boolean focusable)
Changes the focusability of the popup window.
voidsetHeight(int height) Sets the popup’s requested height.
voidsetIgnoreCheekPress() 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.
voidsetInputMethodMode(int mode) Control how the popup operates with an input method: one ofINPUT_METHOD_FROM_FOCUSABLE,INPUT_METHOD_NEEDED, orINPUT_METHOD_NOT_NEEDED.
voidsetIsClippedToScreen(boolean enabled)
Clip this popup window to the screen, but not to the containing window.
voidsetIsLaidOutInScreen(boolean enabled)
Allows the popup window to force the flagWindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, overriding default behavior.
voidsetOnDismissListener(PopupWindow.OnDismissListeneronDismissListener) Sets the listener to be called when the window is dismissed.
voidsetOutsideTouchable(boolean touchable)
Controls whether the pop-up will be informed of touch events outside of its window.
voidsetOverlapAnchor(boolean overlapAnchor) Sets whether the popup window should overlap its anchor view when displayed as a drop-down.
voidsetSoftInputMode(int mode) Sets the operating mode for the soft input area.
voidsetSplitTouchEnabled(boolean enabled)
Allows the popup window to split touches across other windows that also support split touch.
voidsetTouchInterceptor(View.OnTouchListenerl) Set a callback for all touch events being dispatched to the popup window.
voidsetTouchModal(boolean touchModal)
Set whether this window is touch modal or if outside touches will be sent to other windows behind it.
voidsetTouchable(boolean touchable)
Changes the touchability of the popup window.
voidsetWidth(int width) Sets the popup’s requested width.
voidsetWindowLayoutMode(int widthSpec, int heightSpec) This method was deprecated in API level 23. UsesetWidth(int)andsetHeight(int).
voidsetWindowLayoutType(int layoutType) Set the layout type for this window.
voidshowAsDropDown(Viewanchor) Display the content view in a popup window anchored to the bottom-left corner of the anchor view.
voidshowAsDropDown(Viewanchor, int xoff, int yoff, int gravity) Displays the content view in a popup window anchored to the corner of another view.
voidshowAsDropDown(Viewanchor, 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.
voidshowAtLocation(Viewparent, int gravity, int x, int y)
Display the content view in a popup window at the specified location.
voidupdate(Viewanchor, int width, int height) Updates the position and the dimension of the popup window.
voidupdate(Viewanchor, int xoff, int yoff, int width, int height) Updates the position and the dimension of the popup window.
voidupdate(int width, int height) Updates the dimension of the popup window.
voidupdate() Updates the state of the popup window, if it is currently being displayed, from the currently set state.
voidupdate(int x, int y, int width, int height, boolean force) Updates the position and the dimension of the popup window.
voidupdate(int x, int y, int width, int height) Updates the position and the dimension of the popup window.

| ### Inherited methods |
|———————–|—|
| From classjava.lang.Object |——————————————————————————–|———————————————————————————————————————————————————————————————————————————————————————————–| | Object | clone() Creates and returns a copy of this object. | | boolean | equals(Objectobj) Indicates whether some other object is “equal to” this one. | | void | finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | finalClass<?> | getClass() Returns the runtime class of thisObject. | | int | hashCode() Returns a hash code value for the object. | | final void | notify() Wakes up a single thread that is waiting on this object’s monitor. | | final void | notifyAll() Wakes up all threads that are waiting on this object’s monitor. | | String | toString() Returns a string representation of the object. | | final void | wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by beingnotified orinterrupted, or until a certain amount of real time has elapsed. | | final void | wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by beingnotified orinterrupted, or until a certain amount of real time has elapsed. | | final void | wait() Causes the current thread to wait until it is awakened, typically by beingnotified orinterrupted. | ||

XML attributes

android:overlapAnchor

Whether the popup window should overlap its anchor view.

May be a boolean value, such as “true” or “false“.

android:popupAnimationStyle

The animation style to use for the popup window.

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

android:popupBackground

The background to use for the popup window.

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

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

Related methods:

android:popupElevation

Window elevation to use for the popup window.

May 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), and mm (millimeters).

Related methods:

android:popupEnterTransition

Transition used to move views into the popup window.

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

Related methods:

android:popupExitTransition

Transition used to move views out of the popup window.

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

Related methods:

Constants

INPUT_METHOD_FROM_FOCUSABLE

Added inAPI level 3

public static final int INPUT_METHOD_FROM_FOCUSABLE

Mode forsetInputMethodMode(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 inAPI level 3

public static final int INPUT_METHOD_NEEDED

Mode forsetInputMethodMode(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 inAPI level 3

public static final int INPUT_METHOD_NOT_NEEDED

Mode forsetInputMethodMode(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 inAPI level 1

public 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 inAPI level 1

public PopupWindow (Context context)

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

The popup does provide a background.

Parameters
contextContext

PopupWindow

Added inAPI level 1

public PopupWindow (Context context, 
                AttributeSet attrs)

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

The popup does provide a background.

Parameters
contextContext
attrsAttributeSet

PopupWindow

Added inAPI level 1

public 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
contextContext
attrsAttributeSet
defStyleAttrint

PopupWindow

Added inAPI level 11

public 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
contextContext
attrsAttributeSet
defStyleAttrint
defStyleResint

PopupWindow

Added inAPI level 1

public PopupWindow (View contentView)

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

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

Parameters
contentViewView: the popup’s content

PopupWindow

Added inAPI level 1

public PopupWindow (View contentView, 
                int width, 
                int height)

Create a new non focusable popup window which can display thecontentView. 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
contentViewView: the popup’s content
widthint: the popup’s width
heightint: the popup’s height

PopupWindow

Added inAPI level 1

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

Create a new popup window which can display thecontentView. 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
contentViewView: the popup’s content
widthint: the popup’s width
heightint: the popup’s height
focusableboolean: true if the popup can be focused, false otherwise

PopupWindow

Added inAPI level 1

public 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
widthint: the popup’s width
heightint: the popup’s height

Public methods

dismiss

Added inAPI level 1

public void dismiss ()

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

See also:

getAnimationStyle

Added inAPI level 1

public int getAnimationStyle ()

Return the animation style to use the popup appears and disappears

Returns
intthe animation style to use the popup appears and disappears

getBackground

Added inAPI level 1

public Drawable getBackground ()

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

Related XML Attributes:

Returns
Drawablethe background drawable ornullif not set

See also:

getContentView

Added inAPI level 1

public View getContentView ()

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

Returns
ViewaViewrepresenting the popup’s content

See also:

getElevation

Added inAPI level 21

public float getElevation ()

Related XML Attributes:

Returns
floatthe elevation for this popup window in pixels

See also:

getEnterTransition

Added inAPI level 24

public Transition getEnterTransition ()

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

Related XML Attributes:

Returns
Transitionthe enter transition, ornullif not set

See also:

getEpicenterBounds

Added inAPI level 29

public Rect getEpicenterBounds ()

Returns bounds which are used as a center of the enter and exit transitions.

Transitions use Rect, referred to as the epicenter, to orient the direction of travel. For popup windows, the anchor view bounds are used as the default epicenter.

SeeTransition.setEpicenterCallback(EpicenterCallback)for more information about how transition epicenters work.

Returns
Rectbounds relative to anchor view, ornullif not set

See also:

getExitTransition

Added inAPI level 24

public Transition getExitTransition ()

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

Related XML Attributes:

Returns
Transitionthe exit transition, ornullif not set

See also:

getHeight

Added inAPI level 1

public int getHeight ()

Returns the popup’s requested height. May be a layout constant such asLayoutParams.WRAP_CONTENTorLayoutParams.MATCH_PARENT.

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

Returns
intthe popup height in pixels or a layout constant

See also:

getInputMethodMode

Added inAPI level 3

public int getInputMethodMode ()

Return the current value insetInputMethodMode(int).

Returns
int

See also:

getMaxAvailableHeight

Added inAPI level 1

public 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
anchorView: The view on which the popup window must be anchored. This value cannot benull.
Returns
intThe maximum available height for the popup to be completely shown.

getMaxAvailableHeight

Added inAPI level 3

public 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
anchorView: The view on which the popup window must be anchored. This value cannot benull.
yOffsetint: y offset from the view’s bottom edge
Returns
intThe maximum available height for the popup to be completely shown.

getMaxAvailableHeight

Added inAPI level 24

public 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
anchorView: The view on which the popup window must be anchored. This value cannot benull.
yOffsetint: y offset from the view’s bottom edge
ignoreBottomDecorationsboolean: if true, the height returned will be all the way to the bottom of the display, ignoring any bottom decorations
Returns
intThe maximum available height for the popup to be completely shown.

getOverlapAnchor

Added inAPI level 23

public boolean getOverlapAnchor ()

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

Returns
booleanWhether the popup should overlap its anchor.

See also:

getSoftInputMode

Added inAPI level 4

public int getSoftInputMode ()

Returns the current value insetSoftInputMode(int).

Returns
intValue is either0or a combination ofWindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED,WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED,WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN,WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN,WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE,WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING, andWindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION

See also:

getWidth

Added inAPI level 1

public int getWidth ()

Returns the popup’s requested width. May be a layout constant such asLayoutParams.WRAP_CONTENTorLayoutParams.MATCH_PARENT.

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

Returns
intthe popup width in pixels or a layout constant

See also:

getWindowLayoutType

Added inAPI level 23

public int getWindowLayoutType ()

Returns the layout type for this window.

Returns
int

See also:

isAboveAnchor

Added inAPI level 3

public 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 aftershowAsDropDown(android.view.View)orshowAsDropDown(android.view.View, int, int)was invoked.

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

isAttachedInDecor

Added inAPI level 22

public boolean isAttachedInDecor ()

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

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

See also:

isClippedToScreen

Added inAPI level 29

public boolean isClippedToScreen ()

Indicates whether this popup will be clipped to the screen and not to the containing window

Returns
booleantrue if popup will be clipped to the screen instead of the window, false otherwise

See also:

isClippingEnabled

Added inAPI level 3

public boolean isClippingEnabled ()

Indicates whether clipping of the popup window is enabled.

Returns
booleantrue if the clipping is enabled, false otherwise

See also:

isFocusable

Added inAPI level 1

public boolean isFocusable ()

Indicate whether the popup window can grab the focus.

Returns
booleantrue if the popup is focusable, false otherwise

See also:

isLaidOutInScreen

Added inAPI level 29

public boolean isLaidOutInScreen ()

Indicates whether the popup window will be forced into using absolute screen coordinates for positioning.

Returns
booleantrue if the window will always be positioned in screen coordinates.

See also:

isOutsideTouchable

Added inAPI level 3

public boolean isOutsideTouchable ()

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

Returns
booleantrue if the popup is outside touchable, false otherwise

See also:

isShowing

Added inAPI level 1

public boolean isShowing ()

Indicate whether this popup window is showing on screen.

Returns
booleantrue if the popup is showing, false otherwise

isSplitTouchEnabled

Added inAPI level 11

public boolean isSplitTouchEnabled ()

Indicates whether the popup window supports splitting touches.

Returns
booleantrue if the touch splitting is enabled, false otherwise

See also:

isTouchModal

Added inAPI level 29

public boolean isTouchModal ()

Indicates whether outside touches will be sent to this window or other windows behind it

Returns
booleantrue if touches will be sent to this window, false otherwise

See also:

isTouchable

Added inAPI level 3

public boolean isTouchable ()

Indicates whether the popup window receives touch events.

Returns
booleantrue if the popup is touchable, false otherwise

See also:

setAnimationStyle

Added inAPI level 1

public 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 theupdate()methods.

Parameters
animationStyleint: 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 inAPI level 22

public 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 flagWindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR.

By default the flag is set on SDK versionBuild.VERSION_CODES.LOLLIPOP_MR1or greater and cleared on lesser SDK versions.

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

See also:

setBackgroundDrawable

Added inAPI level 1

public void setBackgroundDrawable (Drawable background)

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

Related XML Attributes:

Parameters
backgroundDrawable: the popup’s background

See also:

setClippingEnabled

Added inAPI level 3

public 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 theupdate()methods.

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

See also:

setContentView

Added inAPI level 1

public void setContentView (View contentView)

Change the popup’s content. The content is represented by an instance ofView.

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

Parameters
contentViewView: the new content for the popup

See also:

setElevation

Added inAPI level 21

public void setElevation (float elevation)

Specifies the elevation for this popup window.

Related XML Attributes:

Parameters
elevationfloat: the popup’s elevation in pixels

See also:

setEnterTransition

Added inAPI level 23

public void setEnterTransition (Transition enterTransition)

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

Related XML Attributes:

Parameters
enterTransitionTransition: the enter transition, ornullto clear

See also:

setEpicenterBounds

Added inAPI level 29

public void setEpicenterBounds (Rect bounds)

Sets the bounds used as the epicenter of the enter and exit transitions.

Transitions use Rect, referred to as the epicenter, to orient the direction of travel. For popup windows, the anchor view bounds are used as the default epicenter.

SeeTransition.setEpicenterCallback(EpicenterCallback)for more information about how transition epicenters work.

Parameters
boundsRect: the epicenter bounds relative to the anchor view, ornullto use the default epicenter

See also:

setExitTransition

Added inAPI level 23

public void setExitTransition (Transition exitTransition)

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

Related XML Attributes:

Parameters
exitTransitionTransition: the exit transition, ornullto clear

See also:

setFocusable

Added inAPI level 1

public 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 focusableView. 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 theupdate()methods.

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

See also:

setHeight

Added inAPI level 1

public void setHeight (int height)

Sets the popup’s requested height. May be a layout constant such asLayoutParams.WRAP_CONTENTorLayoutParams.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
heightint: the popup height in pixels or a layout constant

See also:

setIgnoreCheekPress

Added inAPI level 1

public 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 theupdate()methods.

See also:

setInputMethodMode

Added inAPI level 3

public void setInputMethodMode (int mode)

Control how the popup operates with an input method: one ofINPUT_METHOD_FROM_FOCUSABLE,INPUT_METHOD_NEEDED, orINPUT_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 theupdate()methods.

Parameters
modeint

See also:

setIsClippedToScreen

Added inAPI level 29

public void setIsClippedToScreen (boolean enabled)

Clip this popup window to the screen, but not to the containing window.

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 theupdate()methods.

Parameters
enabledboolean: true to clip to the screen.

See also:

setIsLaidOutInScreen

Added inAPI level 29

public void setIsLaidOutInScreen (boolean enabled)

Allows the popup window to force the flagWindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, overriding default behavior. This will cause the popup to be positioned in absolute screen coordinates.

Parameters
enabledboolean: true if the popup should always be positioned in screen coordinates

See also:

setOnDismissListener

Added inAPI level 1

public void setOnDismissListener (PopupWindow.OnDismissListener onDismissListener)

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

Parameters
onDismissListenerPopupWindow.OnDismissListener: The listener.

setOutsideTouchable

Added inAPI level 3

public 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 theupdate()methods.

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

See also:

setOverlapAnchor

Added inAPI level 23

public 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
overlapAnchorboolean: Whether the popup should overlap its anchor.

See also:

setSoftInputMode

Added inAPI level 4

public void setSoftInputMode (int mode)

Sets the operating mode for the soft input area.

Parameters
modeint: The desired mode, seeWindowManager.LayoutParams.softInputModefor the full list Value is either0or a combination ofWindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED,WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED,WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN,WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN,WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE,WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN,WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING, andWindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION

See also:

setSplitTouchEnabled

Added inAPI level 11

public 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
enabledboolean: true if the split touches should be enabled, false otherwise

See also:

setTouchInterceptor

Added inAPI level 3

public void setTouchInterceptor (View.OnTouchListener l)

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

Parameters
lView.OnTouchListener

setTouchModal

Added inAPI level 29

public void setTouchModal (boolean touchModal)

Set whether this window is touch modal or if outside touches will be sent to other windows behind it.

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 theupdate()methods.

Parameters
touchModalboolean: true to sent all outside touches to this window, false to other windows behind it

See also:

setTouchable

Added inAPI level 3

public 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 theupdate()methods.

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

See also:

setWidth

Added inAPI level 1

public void setWidth (int width)

Sets the popup’s requested width. May be a layout constant such asLayoutParams.WRAP_CONTENTorLayoutParams.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
widthint: the popup width in pixels or a layout constant

See also:

setWindowLayoutMode

Added inAPI level 3
Deprecated inAPI level 23

public void setWindowLayoutMode (int widthSpec, 
                int heightSpec)

This method was deprecated in API level 23.
UsesetWidth(int)andsetHeight(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 supplyViewGroup.LayoutParams.WRAP_CONTENTorViewGroup.LayoutParams.MATCH_PARENTto 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
widthSpecint: an explicit width measure spec mode, eitherViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.MATCH_PARENT, or 0 to use the absolute width.
heightSpecint: an explicit height measure spec mode, eitherViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.MATCH_PARENT, or 0 to use the absolute height.

setWindowLayoutType

Added inAPI level 23

public void setWindowLayoutType (int layoutType)

Set the layout type for this window.

SeeWindowManager.LayoutParams.typefor possible values.

Parameters
layoutTypeint: Layout type for this window.

See also:

showAsDropDown

Added inAPI level 1

public 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
anchorView: the view on which to pin the popup window

See also:

showAsDropDown

Added inAPI level 19

public 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 moveanchorto a different location, the popup will be moved correspondingly.

Parameters
anchorView: the view on which to pin the popup window
xoffint: A horizontal offset from the anchor in pixels
yoffint: A vertical offset from the anchor in pixels
gravityint: Alignment of the popup relative to the anchor

See also:

showAsDropDown

Added inAPI level 1

public 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 moveanchorto a different location, the popup will be moved correspondingly.

Parameters
anchorView: the view on which to pin the popup window
xoffint: A horizontal offset from the anchor in pixels
yoffint: A vertical offset from the anchor in pixels

See also:

showAtLocation

Added inAPI level 1

public 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. SeeWindowManager.LayoutParamsfor more information on how gravity and the x and y parameters are related. Specifying a gravity ofGravity.NO_GRAVITYis similar to specifyingGravity.LEFT | Gravity.TOP.

Parameters
parentView: a parent view to get theView.getWindowToken()token from
gravityint: the gravity which controls the placement of the popup window
xint: the popup’s x location offset
yint: the popup’s y location offset

update

Added inAPI level 1

public 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 forupdate().

Parameters
anchorView: the popup’s anchor view
widthint: the new width in pixels, must be >= 0 or -1 to ignore
heightint: the new height in pixels, must be >= 0 or -1 to ignore

update

Added inAPI level 1

public 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 forupdate().

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

Parameters
anchorView: the popup’s anchor view
xoffint: x offset from the view’s left edge
yoffint: y offset from the view’s bottom edge
widthint: the new width in pixels, must be >= 0 or -1 to ignore
heightint: the new height in pixels, must be >= 0 or -1 to ignore

update

Added inAPI level 4

public 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 forupdate().

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

update

Added inAPI level 3

public void update ()

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

This includes:

update

Added inAPI level 3

public 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 forupdate().

Parameters
xint: the new x location
yint: the new y location
widthint: the new width in pixels, must be >= 0 or -1 to ignore
heightint: the new height in pixels, must be >= 0 or -1 to ignore
forceboolean:trueto reposition the window even if the specified position already seems to correspond to the LayoutParams,falseto only reposition if needed

update

Added inAPI level 1

public 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 forupdate().

Parameters
xint: the new x location
yint: the new y location
widthint: the new width in pixels, must be >= 0 or -1 to ignore
heightint: the new height in pixels, must be >= 0 or -1 to ignore

Leave a Comment

Your email address will not be published. Required fields are marked *