java.lang.Object | |
↳ | android.widget.PopupWindow |
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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PopupWindow.OnDismissListener | Listener that is called when this popup window is dismissed. |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:popupBackground | setBackgroundDrawable(Drawable) | The background to use for the popup window. | |||||||||
android:popupElevation | setElevation(float) | Window elevation to use for 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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new empty, non focusable popup window of dimension (0,0). | |||||||||||
Create a new empty, non focusable popup window of dimension (0,0). | |||||||||||
Create a new empty, non focusable popup window of dimension (0,0). | |||||||||||
Create a new, empty, non focusable popup window of dimension (0,0). | |||||||||||
Create a new empty, non focusable popup window of dimension (0,0). | |||||||||||
Create a new non focusable popup window which can display the contentView. | |||||||||||
Create a new empty, non focusable popup window. | |||||||||||
Create a new non focusable popup window which can display the contentView. | |||||||||||
Create a new popup window which can display the contentView. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Dispose of the popup window. | |||||||||||
Return the animation style to use the popup appears and disappears | |||||||||||
Return the drawable used as the popup window's background.
| |||||||||||
Return the view used as the content of the popup window. | |||||||||||
Return this popup's height MeasureSpec | |||||||||||
Return the current value in
setInputMethodMode(int) .
| |||||||||||
Returns the maximum height that is available for the popup to be
completely shown.
| |||||||||||
Returns the maximum height that is available for the popup to be
completely shown.
| |||||||||||
Returns the current value in
setSoftInputMode(int) .
| |||||||||||
Return this popup's width MeasureSpec | |||||||||||
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).
| |||||||||||
Indicates whether clipping of the popup window is enabled. | |||||||||||
Indicate whether the popup window can grab the focus. | |||||||||||
Indicates whether the popup window will be informed of touch events outside of its window. | |||||||||||
Indicate whether this popup window is showing on screen. | |||||||||||
Indicates whether the popup window supports splitting touches. | |||||||||||
Indicates whether the popup window receives touch events. | |||||||||||
Change the animation style resource for this popup. | |||||||||||
Specifies the background drawable for this popup window.
| |||||||||||
Allows the popup window to extend beyond the bounds of the screen. | |||||||||||
Change the popup's content. | |||||||||||
Specifies the elevation for this popup window.
| |||||||||||
Changes the focusability of the popup window. | |||||||||||
Change the popup's height MeasureSpec If the popup is showing, calling this method will take effect only the next time the popup is shown. | |||||||||||
Set the flag on popup to ignore cheek press eventt; by default this flag
is set to false
which means the pop wont ignore cheek press dispatch events.
| |||||||||||
Control how the popup operates with an input method: one of
INPUT_METHOD_FROM_FOCUSABLE , INPUT_METHOD_NEEDED ,
or INPUT_METHOD_NOT_NEEDED .
| |||||||||||
Sets the listener to be called when the window is dismissed.
| |||||||||||
Controls whether the pop-up will be informed of touch events outside of its window. | |||||||||||
Sets the operating mode for the soft input area.
| |||||||||||
Allows the popup window to split touches across other windows that also support split touch. | |||||||||||
Set a callback for all touch events being dispatched to the popup
window.
| |||||||||||
Changes the touchability of the popup window. | |||||||||||
Change the popup's width MeasureSpec If the popup is showing, calling this method will take effect only the next time the popup is shown. | |||||||||||
Change the width and height measure specs that are given to the window manager by the popup. | |||||||||||
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. | |||||||||||
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. | |||||||||||
Display the content view in a popup window anchored to the bottom-left corner of the anchor view. | |||||||||||
Display the content view in a popup window at the specified location. | |||||||||||
Updates the position and the dimension of the popup window. | |||||||||||
Updates the position and the dimension of the popup window. | |||||||||||
Updates the position and the dimension of the popup window. | |||||||||||
Updates the state of the popup window, if it is currently being displayed,
from the currently set state.
| |||||||||||
Updates the position and the dimension of the popup window. | |||||||||||
Updates the dimension of the popup window. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
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
.
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
.
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.
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.
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.
Create a new empty, non focusable popup window of dimension (0,0).
The popup does provide a background.
Create a new empty, non focusable popup window of dimension (0,0).
The popup does provide a background.
Create a new empty, non focusable popup window of dimension (0,0).
The popup does provide a background.
Create a new, empty, non focusable popup window of dimension (0,0).
The popup does not provide a background.
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.
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.
contentView | the popup's content |
---|
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.
width | the popup's width |
---|---|
height | the popup's 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.
contentView | the popup's content |
---|---|
width | the popup's width |
height | the popup's height |
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.
contentView | the popup's content |
---|---|
width | the popup's width |
height | the popup's height |
focusable | true if the popup can be focused, false otherwise |
Dispose 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.
Return the animation style to use the popup appears and disappears
Return the drawable used as the popup window's background.
null
if not setReturn the view used as the content of the popup window.
View
representing the popup's contentReturn this popup's height MeasureSpec
Return the current value in setInputMethodMode(int)
.
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.
anchor | The view on which the popup window must be anchored. |
---|
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.
anchor | The view on which the popup window must be anchored. |
---|---|
yOffset | y offset from the view's bottom edge |
Returns the current value in setSoftInputMode(int)
.
Return this popup's width MeasureSpec
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.
Indicates whether clipping of the popup window is enabled.
Indicate whether the popup window can grab the focus.
Indicates whether the popup window will be informed of touch events outside of its window.
Indicate whether this popup window is showing on screen.
Indicates whether the popup window supports splitting touches.
Indicates whether the popup window receives touch events.
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.
animationStyle | 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. |
---|
Specifies the background drawable for this popup window. The background
can be set to null
.
background | the popup's background |
---|
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.
enabled | false if the window should be allowed to extend outside of the screen |
---|
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.
contentView | the new content for the popup |
---|
Specifies the elevation for this popup window.
elevation | the popup's elevation in pixels |
---|
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.
focusable | true if the popup should grab focus, false otherwise. |
---|
Change the popup's height MeasureSpec
If the popup is showing, calling this method will take effect only the next time the popup is shown.
height | the height MeasureSpec of the popup |
---|
Set the flag on popup to ignore cheek press eventt; by default this flag is set to false which means the pop wont 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.
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.
Sets the listener to be called when the window is dismissed.
onDismissListener | The listener. |
---|
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.
touchable | true if the popup should receive outside touch events, false otherwise |
---|
Sets the operating mode for the soft input area.
mode | The desired mode, see
softInputMode
for the full list |
---|
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.
enabled | true if the split touches should be enabled, false otherwise |
---|
Set a callback for all touch events being dispatched to the popup window.
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.
touchable | true if the popup should receive touch events, false otherwise |
---|
Change the popup's width MeasureSpec
If the popup is showing, calling this method will take effect only the next time the popup is shown.
width | the width MeasureSpec of the popup |
---|
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.
widthSpec | an explicit width measure spec mode, either
WRAP_CONTENT ,
MATCH_PARENT , or 0 to use the absolute
width. |
---|---|
heightSpec | an explicit height measure spec mode, either
WRAP_CONTENT ,
MATCH_PARENT , or 0 to use the absolute
height.
|
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.
anchor | the view on which to pin the popup window |
---|---|
xoff | A horizontal offset from the anchor in pixels |
yoff | A vertical offset from the anchor in pixels |
gravity | Alignment of the popup relative to the anchor |
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.
anchor | the view on which to pin the popup window |
---|---|
xoff | A horizontal offset from the anchor in pixels |
yoff | A vertical offset from the anchor in pixels |
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.
anchor | the view on which to pin the popup window |
---|
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
.
parent | a parent view to get the getWindowToken() token from |
---|---|
gravity | the gravity which controls the placement of the popup window |
x | the popup's x location offset |
y | the popup's y location offset |
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()
.
anchor | the popup's anchor view |
---|---|
width | the new width, can be -1 to ignore |
height | the new height, can be -1 to ignore |
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()
.
x | the new x location |
---|---|
y | the new y location |
width | the new width, can be -1 to ignore |
height | the new height, can be -1 to ignore |
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.
anchor | the popup's anchor view |
---|---|
xoff | x offset from the view's left edge |
yoff | y offset from the view's bottom edge |
width | the new width, can be -1 to ignore |
height | the new height, can be -1 to ignore |
Updates the state of the popup window, if it is currently being displayed,
from the currently set state. This includes:
setClippingEnabled(boolean)
, setFocusable(boolean)
,
setIgnoreCheekPress()
, setInputMethodMode(int)
,
setTouchable(boolean)
, and setAnimationStyle(int)
.
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()
.
x | the new x location |
---|---|
y | the new y location |
width | the new width, can be -1 to ignore |
height | the new height, can be -1 to ignore |
force | reposition the window even if the specified position already seems to correspond to the LayoutParams |
Updates the dimension of the popup window. Calling this function
also updates the window with the current popup state as described
for update()
.
width | the new width |
---|---|
height | the new height |