Android
android.widget
public class

android.widget.PopupWindow

java.lang.Object
android.widget.PopupWindow

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

Summary

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 defStyle)

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()

Dispose 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.

          int  getHeight()

Return this popup's height MeasureSpec

          int  getMaxAvailableHeight(View anchor)
Returns the maximum height that is available for the popup to be completely shown.
          int  getWidth()

Return this popup's width MeasureSpec

          boolean  isFocusable()

Indicate whether the popup window can grab the focus.

          boolean  isShowing()

Indicate whether this popup window is showing on screen.

          void  setAnimationStyle(int animationStyle)

Change the animation style for this popup.

          void  setBackgroundDrawable(Drawable background)

Change the background drawable for this popup window.

          void  setContentView(View contentView)

Change the popup's content.

          void  setFocusable(boolean focusable)

Changes the focusability of the popup window.

          void  setHeight(int height)

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.

          void  setIgnoreCheekPress()
set the flag on popup to ignore cheek press events This method has to be invoked before displaying the content view of the popup for the window flags to take effect and will be ignored if the pop up is already displayed.
          void  setOnDismissListener(PopupWindow.OnDismissListener onDismissListener)
Sets the listener to be called when the window is dismissed.
          void  setWidth(int width)

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.

          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  showAsDropDown(View anchor)

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

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

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

          void  update(int x, int y, 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(View anchor, int width, int height)

Updates the position and the dimension of the popup window.

Methods inherited from class java.lang.Object

Details

Public Constructors

public PopupWindow(Context context)

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

The popup does provide a background.

public PopupWindow(Context context, AttributeSet attrs)

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

The popup does provide a background.

public PopupWindow(Context context, AttributeSet attrs, int defStyle)

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

The popup does provide a background.

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.

public 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 the popup's content

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

width the popup's width
height the popup's height

public 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 the popup's content
width the popup's width
height the popup's height

public 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 the popup's content
width the popup's width
height the popup's height
focusable true if the popup can be focused, false otherwise

Public Methods

public void dismiss()

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.

public int getAnimationStyle()

Return the animation style to use the popup appears and disappears

Returns

  • the animation style to use the popup appears and disappears

public Drawable getBackground()

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

Returns

  • the background drawable or null

public View getContentView()

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

Returns

  • a View representing the popup's content

public int getHeight()

Return this popup's height MeasureSpec

Returns

  • the height MeasureSpec of the popup

See Also

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

anchor The view on which the popup window must be anchored.

Returns

  • The maximum available height for the popup to be completely shown.

public int getWidth()

Return this popup's width MeasureSpec

Returns

  • the width MeasureSpec of the popup

See Also

public boolean isFocusable()

Indicate whether the popup window can grab the focus.

Returns

  • true if the popup is focusable, false otherwise

public boolean isShowing()

Indicate whether this popup window is showing on screen.

Returns

  • true if the popup is showing, false otherwise

public void setAnimationStyle(int animationStyle)

Change the animation style for this popup.

Parameters

animationStyle animation style to use when the popup appears and disappears

public void setBackgroundDrawable(Drawable background)

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

Parameters

background the popup's background

public 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 the new content for the popup

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 focusable View.

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

Parameters

focusable true if the popup should grab focus, false otherwise

public void setHeight(int height)

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.

Parameters

height the height MeasureSpec of the popup

public void setIgnoreCheekPress()

set the flag on popup to ignore cheek press events This method has to be invoked before displaying the content view of the popup for the window flags to take effect and will be ignored if the pop up is already displayed. By default this flag is set to false which means the pop wont ignore cheek press dispatch events.

public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener)

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

Parameters

onDismissListener The listener.

public void setWidth(int width)

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.

Parameters

width the width MeasureSpec of the popup

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.

Parameters

anchor the view on which to pin the popup window

See Also

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

anchor the view on which to pin the popup window

See Also

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. 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 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

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.

Parameters

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

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.

Parameters

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

public void update(View anchor, 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.

Parameters

anchor the popup's anchor view
width the new width, can be -1 to ignore
height the new height, can be -1 to ignore
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48