Build 1.0_r1(from source)

android.widget
Class PopupWindow

java.lang.Object
  extended by android.widget.PopupWindow

public class PopupWindow
extends Object

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.

See Also:
AutoCompleteTextView, Spinner

Nested Class Summary
(package private) static interface PopupWindow.OnDismissListener
          Listener that is called when this popup window is dismissed.
 
Constructor Summary
PopupWindow()
          Create a new empty, non focusable popup window of dimension (0,0).
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(int width, int height)
          Create a new empty, non focusable popup window.
PopupWindow(View contentView)
          Create a new non focusable popup window which can display the contentView.
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.
 
Method Summary
 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
 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
 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)
          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(int x, int y, 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.
 void update(View anchor, int xoff, int yoff, int width, int height)
          Updates the position and the dimension of the popup window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopupWindow

public PopupWindow(Context context)

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

The popup does provide a background.


PopupWindow

public PopupWindow(Context context,
                   AttributeSet attrs)

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

The popup does provide a background.


PopupWindow

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.


PopupWindow

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

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

PopupWindow

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

PopupWindow

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

PopupWindow

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
Method Detail

getBackground

public Drawable getBackground()

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

Returns:
the background drawable or null

setBackgroundDrawable

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

getAnimationStyle

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

setIgnoreCheekPress

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.


setAnimationStyle

public void setAnimationStyle(int animationStyle)

Change the animation style for this popup.

Parameters:
animationStyle - animation style to use when the popup appears and disappears

getContentView

public View getContentView()

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

Returns:
a View representing the popup's content
See Also:
setContentView(android.view.View)

setContentView

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
See Also:
getContentView(), isShowing()

isFocusable

public boolean isFocusable()

Indicate whether the popup window can grab the focus.

Returns:
true if the popup is focusable, false otherwise
See Also:
setFocusable(boolean)

setFocusable

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
See Also:
isFocusable(), isShowing()

getHeight

public int getHeight()

Return this popup's height MeasureSpec

Returns:
the height MeasureSpec of the popup
See Also:
setHeight(int)

setHeight

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
See Also:
getHeight(), isShowing()

getWidth

public int getWidth()

Return this popup's width MeasureSpec

Returns:
the width MeasureSpec of the popup
See Also:
setWidth(int)

setWidth

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
See Also:
getWidth(), isShowing()

isShowing

public boolean isShowing()

Indicate whether this popup window is showing on screen.

Returns:
true if the popup is showing, false otherwise

showAtLocation

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 Gravity.NO_GRAVITY is similar to specifying Gravity.LEFT | Gravity.TOP.

Parameters:
parent - a parent view to get the View.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

showAsDropDown

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

showAsDropDown

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

getMaxAvailableHeight

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.

dismiss

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.

See Also:
showAsDropDown(android.view.View)

setOnDismissListener

public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener)
Sets the listener to be called when the window is dismissed.

Parameters:
onDismissListener - The listener.

update

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

update

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

update

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

Build 1.0_r1(from source)

Please submit a feedback, bug or feature