public class EasyPopup
extends java.lang.Object
implements android.widget.PopupWindow.OnDismissListener
| Modifier and Type | Class and Description |
|---|---|
static interface |
EasyPopup.OnAttachedWindowListener
PopupWindow是否显示在window中
用于获取准确的PopupWindow宽高,可以重新设置偏移量
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
isBackgroundDim
弹出pop时,背景是否变暗
|
protected int |
mAnimationStyle |
protected android.view.View |
mContentView
contentView
|
protected int |
mDimColor
背景变暗颜色
|
protected float |
mDimValue
背景变暗时透明度
|
protected android.view.ViewGroup |
mDimView
背景变暗的view
|
protected android.transition.Transition |
mEnterTransition |
protected android.transition.Transition |
mExitTransition |
protected boolean |
mFocusable
获取焦点
|
protected int |
mHeight |
protected int |
mLayoutId
布局id
|
protected boolean |
mOutsideTouchable
是否触摸之外dismiss
|
protected int |
mWidth
宽高
|
| Constructor and Description |
|---|
EasyPopup(android.content.Context context) |
| Modifier and Type | Method and Description |
|---|---|
<T extends EasyPopup> |
createPopup()
创建popup
|
void |
dismiss()
消失
|
android.view.View |
getContentView()
获取PopupWindow中加载的view
|
android.content.Context |
getContext()
获取context
|
android.widget.PopupWindow |
getPopupWindow()
获取PopupWindow对象
|
<T extends android.view.View> |
getView(int viewId)
获取view
|
boolean |
isShow() |
void |
onDismiss() |
protected void |
onPopupWindowCreated(android.widget.PopupWindow popupWindow)
PopupWindow对象创建完成
|
protected void |
onPopupWindowDismiss()
PopupWindow消失
|
protected void |
onPopupWindowViewCreated(android.view.View contentView)
PopupWindow的加载view创建完成
|
<T extends EasyPopup> |
setAnchorView(android.view.View view) |
<T extends EasyPopup> |
setAnimationStyle(int animationStyle) |
<T extends EasyPopup> |
setBackgroundDimEnable(boolean isDim)
背景变暗支持api>=18
|
<T extends EasyPopup> |
setContentView(int layoutId) |
<T extends EasyPopup> |
setContentView(int layoutId,
int width,
int height) |
<T extends EasyPopup> |
setContentView(android.view.View contentView)
设置自定义布局内容
|
<T extends EasyPopup> |
setContentView(android.view.View contentView,
int width,
int height) |
<T extends EasyPopup> |
setDimColor(int color)
设置背景变暗的颜色
|
<T extends EasyPopup> |
setDimValue(float dimValue)
设置背景变暗的透明度
|
<T extends EasyPopup> |
setDimView(android.view.ViewGroup dimView)
设置背景变暗的view
|
<T extends EasyPopup> |
setEnterTransition(android.transition.Transition enterTransition) |
<T extends EasyPopup> |
setExitTransition(android.transition.Transition exitTransition) |
<T extends EasyPopup> |
setFocusable(boolean focusable) |
<T extends EasyPopup> |
setFocusAndOutsideEnable(boolean focusAndOutsideEnable)
是否可以点击PopupWindow之外的地方dismiss
|
<T extends EasyPopup> |
setHeight(int height) |
<T extends EasyPopup> |
setHorizontalGravity(int horizontalGravity) |
<T extends EasyPopup> |
setOffsetX(int offsetX) |
<T extends EasyPopup> |
setOffsetY(int offsetY) |
<T extends EasyPopup> |
setOnAttachedWindowListener(EasyPopup.OnAttachedWindowListener listener) |
<T extends EasyPopup> |
setOnDismissListener(android.widget.PopupWindow.OnDismissListener listener)
设置监听器
|
<T extends EasyPopup> |
setOutsideTouchable(boolean outsideTouchable) |
<T extends EasyPopup> |
setVerticalGravity(int verticalGravity) |
<T extends EasyPopup> |
setWidth(int width) |
void |
showAsDropDown()
使用此方法需要在创建的时候调用setAnchorView()等属性设置
setAnchorView() |
void |
showAsDropDown(android.view.View anchor) |
void |
showAsDropDown(android.view.View anchor,
int offsetX,
int offsetY)
PopupWindow自带的显示方法
|
void |
showAsDropDown(android.view.View anchor,
int offsetX,
int offsetY,
int gravity) |
void |
showAtAnchorView()
相对anchor view显示
|
void |
showAtAnchorView(android.view.View anchor,
int vertGravity,
int horizGravity)
相对anchor view显示,适用 宽高不为match_parent
|
void |
showAtAnchorView(android.view.View anchor,
int vertGravity,
int horizGravity,
int x,
int y)
相对anchor view显示,适用 宽高不为match_parent
|
void |
showAtLocation(android.view.View parent,
int gravity,
int offsetX,
int offsetY) |
protected android.view.View mContentView
protected int mLayoutId
protected boolean mFocusable
protected boolean mOutsideTouchable
protected int mWidth
protected int mHeight
protected int mAnimationStyle
protected boolean isBackgroundDim
protected float mDimValue
protected int mDimColor
protected android.view.ViewGroup mDimView
protected android.transition.Transition mEnterTransition
protected android.transition.Transition mExitTransition
public <T extends EasyPopup> T createPopup()
T - protected void onPopupWindowCreated(android.widget.PopupWindow popupWindow)
popupWindow - protected void onPopupWindowViewCreated(android.view.View contentView)
contentView - protected void onPopupWindowDismiss()
public <T extends EasyPopup> T setContentView(android.view.View contentView)
T - contentView - public <T extends EasyPopup> T setContentView(int layoutId)
public <T extends EasyPopup> T setContentView(android.view.View contentView, int width, int height)
public <T extends EasyPopup> T setContentView(int layoutId, int width, int height)
public <T extends EasyPopup> T setWidth(int width)
public <T extends EasyPopup> T setHeight(int height)
public <T extends EasyPopup> T setAnchorView(android.view.View view)
public <T extends EasyPopup> T setVerticalGravity(int verticalGravity)
public <T extends EasyPopup> T setHorizontalGravity(int horizontalGravity)
public <T extends EasyPopup> T setOffsetX(int offsetX)
public <T extends EasyPopup> T setOffsetY(int offsetY)
public <T extends EasyPopup> T setAnimationStyle(int animationStyle)
public <T extends EasyPopup> T setFocusable(boolean focusable)
public <T extends EasyPopup> T setOutsideTouchable(boolean outsideTouchable)
public <T extends EasyPopup> T setFocusAndOutsideEnable(boolean focusAndOutsideEnable)
focusAndOutsideEnable - public <T extends EasyPopup> T setBackgroundDimEnable(boolean isDim)
isDim - public <T extends EasyPopup> T setDimValue(float dimValue)
T - dimValue - public <T extends EasyPopup> T setDimColor(int color)
T - color - public <T extends EasyPopup> T setDimView(android.view.ViewGroup dimView)
T - dimView - public <T extends EasyPopup> T setEnterTransition(android.transition.Transition enterTransition)
public <T extends EasyPopup> T setExitTransition(android.transition.Transition exitTransition)
public <T extends EasyPopup> T setOnDismissListener(android.widget.PopupWindow.OnDismissListener listener)
listener - public <T extends EasyPopup> T setOnAttachedWindowListener(EasyPopup.OnAttachedWindowListener listener)
public void showAsDropDown()
setAnchorView()public void showAsDropDown(android.view.View anchor,
int offsetX,
int offsetY)
anchor - offsetX - offsetY - public void showAsDropDown(android.view.View anchor)
public void showAsDropDown(android.view.View anchor,
int offsetX,
int offsetY,
int gravity)
public void showAtLocation(android.view.View parent,
int gravity,
int offsetX,
int offsetY)
public void showAtAnchorView()
使用此方法需要在创建的时候调用setAnchorView()等属性设置setAnchorView()
注意:如果使用 VerticalGravity 和 HorizontalGravity 时,请确保使用之后 PopupWindow 没有超出屏幕边界, 如果超出屏幕边界,VerticalGravity 和 HorizontalGravity 可能无效,从而达不到你想要的效果。
public void showAtAnchorView(android.view.View anchor,
int vertGravity,
int horizGravity)
注意:如果使用 VerticalGravity 和 HorizontalGravity 时,请确保使用之后 PopupWindow 没有超出屏幕边界, 如果超出屏幕边界,VerticalGravity 和 HorizontalGravity 可能无效,从而达不到你想要的效果。 *
anchor - vertGravity - horizGravity - public void showAtAnchorView(android.view.View anchor,
int vertGravity,
int horizGravity,
int x,
int y)
注意:如果使用 VerticalGravity 和 HorizontalGravity 时,请确保使用之后 PopupWindow 没有超出屏幕边界, 如果超出屏幕边界,VerticalGravity 和 HorizontalGravity 可能无效,从而达不到你想要的效果。
anchor - vertGravity - 垂直方向的对齐方式horizGravity - 水平方向的对齐方式x - 水平方向的偏移y - 垂直方向的偏移public android.view.View getContentView()
public android.content.Context getContext()
public android.widget.PopupWindow getPopupWindow()
public <T extends android.view.View> T getView(int viewId)
T - viewId - public void dismiss()
public boolean isShow()
public void onDismiss()
onDismiss in interface android.widget.PopupWindow.OnDismissListener