public abstract class BasePopupWindow extends Object implements BasePopup, PopupWindow.OnDismissListener
这是一个快速实现PopupWindow的基类,本基类易于扩展,并且几乎没有使用限制,便于您快速实现各种各样的PopupWindow。
BasePopup已经为您内部实现了多数实际使用遇到的复杂场景功能,比如背景模糊、展现动画、收起动画等。 这些功能大多数都是可以由您自行定制或者决定是否执行,
BasePopup.onCreateContentView()):
onCreateShowAnimation() 该方法决定您的PopupWindow将会以怎样的动画展示出来,可以返回为 nullonCreateDismissAnimation() 该方法决定您的PopupWindow将会以怎样的动画小时,可以返回为 nullBasePopup.onCreateContentView() 该方法决定您的PopupWindow的contentView,一般不可以返回空值【NotNull】类似于PopupWindow.setContentView(View),
但建议使用基类方法createPopupById(int)
在您定义好基本的几个方法后,您可以创建PopupWindow实例并直接调用showPopupWindow()方法即可
example:
DemoPopup popup = new DemoPopup(context);
popup.showPopupWindow();
setBackgroundColor(int)来制定,默认情况下,该颜色为#8f000000setAlignBackground(boolean)把Mask层对齐到与您的PopupWindow主体一致setBlurBackgroundEnable(boolean)为true,默认情况下模糊对象是当前decorView,如果您需要针对模糊某个View,
请设置setBlurOption(PopupBlurOption)以及PopupBlurOption.setBlurView(View)传入。setBlurBackgroundEnable(boolean, OnBlurOptionInitListener),在BasePopupWindow.OnBlurOptionInitListener.onCreateBlurOption(PopupBlurOption)中进行修改
重大版本修正记录:
| 限定符和类型 | 类和说明 |
|---|---|
static class |
BasePopupWindow.GravityMode |
static interface |
BasePopupWindow.OnBeforeShowCallback |
static interface |
BasePopupWindow.OnBlurOptionInitListener |
static class |
BasePopupWindow.OnDismissListener |
| 限定符和类型 | 字段和说明 |
|---|---|
static boolean |
DEBUG |
static int |
DEFAULT_BACKGROUND_COLOR |
static int |
MATCH_PARENT |
static int |
WRAP_CONTENT |
| 构造器和说明 |
|---|
BasePopupWindow(Context context) |
BasePopupWindow(Context context,
boolean delayInit)
支持延迟加载的PopupWindow
|
BasePopupWindow(Context context,
int width,
int height) |
BasePopupWindow(Context context,
int width,
int height,
boolean delayInit)
支持延迟加载的PopupWindow
|
| 限定符和类型 | 方法和说明 |
|---|---|
BasePopupWindow |
attachLifeCycle(Object owner)
绑定lifecycle
|
boolean |
callDismissAtOnce() |
View |
createPopupById(int layoutId)
这个方法封装了LayoutInflater.from(context).inflate,方便您设置PopupWindow所用的xml
|
void |
delayInit()
延迟初始化
|
protected float |
dipToPx(float dip) |
void |
dismiss()
取消一个PopupWindow,如果有退出动画,PopupWindow的消失将会在动画结束后执行
|
void |
dismiss(boolean animateDismiss)
取消一个PopupWindow,如果有退出动画,PopupWindow的消失将会在动画结束后执行
|
void |
dismissWithOutAnimate()
直接消掉PopupWindow而不需要动画
|
<T extends View> |
findViewById(int id)
还在用View.findViewById么,,,不如试试这款?
|
View |
getContentView()
获取PopupWindow的根布局
|
Activity |
getContext()
获取context,请留意是否为空
null
|
protected Animation |
getDefaultAlphaAnimation()
生成默认的AlphaAnimation
|
protected Animation |
getDefaultAlphaAnimation(boolean in)
生成默认的AlphaAnimation
|
protected Animation |
getDefaultScaleAnimation()
生成自定义ScaleAnimation
|
protected Animation |
getDefaultScaleAnimation(boolean in)
生成自定义ScaleAnimation
|
protected AnimatorSet |
getDefaultSlideFromBottomAnimationSet()
从下方滑动上来
|
Animation |
getDismissAnimation() |
Animator |
getDismissAnimator() |
View |
getDisplayAnimateView()
|
int |
getHeight()
获取PoupWindow的高度。
|
int |
getOffsetX() |
int |
getOffsetY() |
BasePopupWindow.OnBeforeShowCallback |
getOnBeforeShowCallback() |
BasePopupWindow.OnDismissListener |
getOnDismissListener() |
Drawable |
getPopupBackground()
获取当前PopupWindow背景
|
int |
getPopupGravity() |
PopupWindow |
getPopupWindow()
获取PopupWindow实例
|
protected Animation |
getScaleAnimation(float fromX,
float toX,
float fromY,
float toY,
int pivotXType,
float pivotXValue,
int pivotYType,
float pivotYValue)
生成ScaleAnimation
time=300
|
int |
getScreenHeight()
获取屏幕高度(px)
|
int |
getScreenWidth()
获取屏幕宽度(px)
|
Animation |
getShowAnimation() |
Animator |
getShowAnimator() |
protected Animation |
getTranslateVerticalAnimation(float start,
float end,
int durationMillis)
生成TranslateAnimation(相对于parent)
|
protected Animation |
getTranslateVerticalAnimation(int start,
int end,
int durationMillis)
生成TranslateAnimation
|
int |
getWidth()
获取PoupWindow的宽度。
|
boolean |
isAllowDismissWhenTouchOutside() |
boolean |
isAllowInterceptTouchEvent()
已过时。
please use
isOutSideTouchable() |
boolean |
isAutoLocatePopup() |
boolean |
isOutSideTouchable()
外部是否可以点击
|
boolean |
isPopupFadeEnable()
当前PopupWindow是否设置了淡入淡出效果
|
boolean |
isShowing()
PopupWindow是否处于展示状态
|
BasePopupWindow |
linkTo(View anchorView)
允许PopupWindow跟某个anchorView关联,其位置,可视性将会跟anchorView同步>
WARN:非常不建议在anchorView频繁变化的情况下使用背景模糊,这会导致较大的性能消耗。 |
void |
onAnchorBottom()
在anchorView下方显示,autoLocatePopup为true时适用
|
void |
onAnchorBottom(View mPopupView,
View anchorView)
已过时。
因为contentView和anchorView应由用户自行保存决定,此处不再返回
|
void |
onAnchorTop()
在anchorView上方显示,autoLocatePopup为true时适用
|
void |
onAnchorTop(View mPopupView,
View anchorView)
已过时。
因为contentView和anchorView应由用户自行保存决定,此处不再返回
|
boolean |
onBackPressed()
捕捉返回键事件
|
boolean |
onBeforeDismiss() |
protected View |
onCreateAnimateView()
|
protected Animation |
onCreateDismissAnimation()
该方法决定您的PopupWindow将会以怎样的动画消失,可以返回为
null
如果返回不为空,则在返回动画播放结束后触发 PopupWindow.dismiss()
本类提供一些简单的动画方法:
getDefaultAlphaAnimation(boolean) ()}:得到一个默认进入的渐变动画
getDefaultScaleAnimation(boolean) ()}:得到一个默认的放大缩小动画
getTranslateVerticalAnimation(float, float, int) ()}:快速获取垂直方向的动画
如果需要用到属性动画,请覆写onCreateDismissAnimator() ()} |
protected Animator |
onCreateDismissAnimator()
|
protected Animation |
onCreateShowAnimation()
该方法决定您的PopupWindow将会以怎样的动画展示出来,可以返回为
null
本类提供一些简单的动画方法:
getDefaultAlphaAnimation():得到一个默认进入的渐变动画
getDefaultScaleAnimation():得到一个默认的放大缩小动画
getTranslateVerticalAnimation(float, float, int) ()}:快速获取垂直方向的动画
如果需要用到属性动画,请覆写onCreateShowAnimator() |
protected Animator |
onCreateShowAnimator()
|
void |
onDismiss() |
boolean |
onDispatchKeyEvent(KeyEvent event)
捕捉keyevent
|
protected View |
onFindDecorView(Activity activity)
指定DecorView,对于一些在弹窗上的弹窗(例如Dialog)里,其windowToken需要是Dialog的window才可以使PopupWindow悬浮在它的上面
|
boolean |
onInterceptTouchEvent(MotionEvent event)
捕捉interceptTouchEvent
|
boolean |
onOutSideTouch()
PopupWindow外的事件点击回调,请注意您的PopupWindow大小
|
boolean |
onTouchEvent(MotionEvent event)
捕捉touchevent
|
BasePopupWindow |
removeLifeCycle(Object owner)
解绑lifecycle
|
BasePopupWindow |
setAdjustInputMethod(boolean needAdjust)
PopupWindow是否需要自适应输入法,为输入法弹出让出区域
|
BasePopupWindow |
setAdjustInputMethod(boolean needAdjust,
int flag)
PopupWindow是否需要自适应输入法,为输入法弹出让出区域
|
BasePopupWindow |
setAlignBackground(boolean isAlignBackground)
设置PopupWindow的背景是否对齐到PopupWindow。
|
BasePopupWindow |
setAlignBackgroundGravity(int gravity)
设置PopupWindow的背景对齐PopupWindow的方式,请传入
Gravity中的值
|
BasePopupWindow |
setAllowDismissWhenTouchOutside(boolean dismissWhenTouchOutside)
已过时。
please use
setOutSideDismiss(boolean) instead |
BasePopupWindow |
setAllowInterceptTouchEvent(boolean touchable)
已过时。
please use
setOutSideTouchable(boolean) instead |
BasePopupWindow |
setAutoLocatePopup(boolean isAutoLocatePopup)
是否自动设置PopupWindow位置
在设定了clipToScreen的情况下 setClipToScreen(boolean)
如果当前屏幕不足以完整显示您的PopupWindow,则PopupWindow会自行布置在其镜像位置。 |
BasePopupWindow |
setAutoShowInputMethod(EditText editText,
boolean autoShow)
PopupWindow在展示的时候自动打开输入法,在传入参数时请务必传入
EditText
|
BasePopupWindow |
setBackground(Drawable background)
设置PopupWindow背景Drawable,默认颜色为#8f000000
|
BasePopupWindow |
setBackground(int drawableIds)
设置PopupWindow背景Drawable,默认颜色为#8f000000
|
BasePopupWindow |
setBackgroundColor(int color)
设置PopupWindow背景颜色,默认颜色为#8f000000
|
BasePopupWindow |
setBackgroundView(View backgroundView)
设置PopupWindow背景View,因为背景全屏的原因,该View将会被强制设为MATCH_PARENT/MATCH_PARENT
|
BasePopupWindow |
setBackPressEnable(boolean backPressEnable)
禁止PopupWindow返回键dismiss
|
BasePopupWindow |
setBlurBackgroundEnable(boolean blurBackgroundEnable)
设置PopupWindow弹出时是否模糊背景。
|
BasePopupWindow |
setBlurBackgroundEnable(boolean blurBackgroundEnable,
BasePopupWindow.OnBlurOptionInitListener optionInitListener)
设置PopupWindow弹出时是否模糊背景。
|
BasePopupWindow |
setBlurOption(PopupBlurOption option)
|
BasePopupWindow |
setClipChildren(boolean clipChildren)
该参数决定popupWindow是否被限制在绘制边界
true:PopupWindow将会被限制边界,其动画不可突破其边界 false:PopupWindow将不会被限制绘制边界,其动画可突破其边界 |
BasePopupWindow |
setClipToScreen(boolean clipToScreen)
该方法用于指定PopupWindow是否可以突破屏幕
true:PopupWindow并不能突破屏幕,如果其高宽超出屏幕高宽,则会自动进行位移 false:PopupWindow可以突破屏幕 如果contentView的宽高大于屏幕宽高,因自动调整,可能会导致 setAutoLocatePopup(boolean)失效 |
static void |
setDebugMode(boolean debugMode) |
BasePopupWindow |
setDismissAnimation(Animation dismissAnimation)
设置退出PopupWindow的动画,详情参考
onCreateDismissAnimation()
|
BasePopupWindow |
setDismissAnimator(Animator dismissAnimator)
设置退出PopupWindow的动画,详情参考
onCreateDismissAnimator()
|
<P extends BasePopupWindow> |
setEventInterceptor(PopupWindowEventInterceptor<P> eventInterceptor)
添加BasePopupWindow事件拦截器
|
BasePopupWindow |
setHeight(int height) |
BasePopupWindow |
setKeepSize(boolean keepSize)
是否保持测量高度
在
setClipToScreen(boolean)为true的情况下,BasePopup会针对剩余高度来调整Popup的大小,因此可能出现实际显示高度过小的情况
该方法可以保持默认测量高度从而阻止BasePopup的自动调整 |
BasePopupWindow |
setMaxHeight(int maxHeight)
设置BasePopup最大高度
|
BasePopupWindow |
setMaxWidth(int maxWidth)
设置BasePopup最大宽度
|
BasePopupWindow |
setMinHeight(int minHeight)
设置BasePopup最小高度
|
BasePopupWindow |
setMinWidth(int minWidth)
设置BasePopup最小宽度
|
BasePopupWindow |
setOffsetX(int offsetX)
设定x位置的偏移量(中心点在popup的左上角)
|
BasePopupWindow |
setOffsetY(int offsetY)
设定y位置的偏移量(中心点在popup的左上角)
|
BasePopupWindow |
setOnBeforeShowCallback(BasePopupWindow.OnBeforeShowCallback mOnBeforeShowCallback)
当您设置了
BasePopupWindow.OnBeforeShowCallback监听之后,在您调用{
showPopupWindow()
showPopupWindow(int)
showPopupWindow(View)
}
任意一个方法,在show之前回回调到该监听器。 |
BasePopupWindow |
setOnDismissListener(BasePopupWindow.OnDismissListener onDismissListener)
设置dismiss监听
|
BasePopupWindow |
setOutSideDismiss(boolean outSideDismiss)
是否允许点击PopupWindow外部时触发dismiss
dismiss popup when touch outside from popup |
BasePopupWindow |
setOutSideTouchable(boolean touchable)
是否允许点击PopupWindow拦截事件。
|
BasePopupWindow |
setPopupAnimationStyle(int animationStyleRes)
设置PopupWindow的动画style针对PopupWindow整体的Window哦
通常情况下,请使用 onCreateDismissAnimation() or onCreateShowAnimator()
|
BasePopupWindow |
setPopupFadeEnable(boolean isPopupFadeAnimate)
当传入true,你的PopupWindow将会淡入显示,淡出消失。
|
BasePopupWindow |
setPopupGravity(BasePopupWindow.GravityMode mode,
int popupGravity)
设置参考方向
Gravity
不跟anchorView联系的情况下,gravity意味着在整个view中的方位 showPopupWindow()
如果跟anchorView联系,gravity意味着以anchorView为中心的方位showPopupWindow(View)
|
BasePopupWindow |
setPopupGravity(int popupGravity)
设置参考方向
Gravity
不跟anchorView联系的情况下,gravity意味着在整个view中的方位 showPopupWindow()
如果跟anchorView联系,gravity意味着以anchorView为中心的方位showPopupWindow(View)
|
BasePopupWindow |
setPopupWindowFullScreen(boolean isFullScreen)
允许PopupWindow覆盖屏幕(包含状态栏)
|
BasePopupWindow |
setShowAnimation(Animation showAnimation)
设置展示PopupWindow的动画,详情参考
onCreateShowAnimation()
|
BasePopupWindow |
setShowAnimator(Animator showAnimator)
设置展示PopupWindow的动画,详情参考
onCreateShowAnimator()
|
BasePopupWindow |
setSoftInputMode(int softInputMode)
设置是否适配输入法
|
protected void |
setViewClickListener(View.OnClickListener listener,
View... views)
这个方法用于简化您为View设置OnClickListener事件,多个View将会使用同一个点击事件
|
BasePopupWindow |
setWidth(int width) |
void |
showPopupWindow()
调用这个方法时,将会展示PopupWindow。
|
void |
showPopupWindow(int anchorViewResid)
传入anchorView的ViewId,方法详情
showPopupWindow(View)
|
void |
showPopupWindow(int x,
int y)
调用这个方法时,将会在指定位置弹出PopupWindow。
|
void |
showPopupWindow(View anchorView)
调用这个方法时,将会展示PopupWindow。
|
void |
update()
啥都不干,单纯的update,简单的说,就是更新你所设置的所有东西~
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。 |
void |
update(float width,
float height)
更新PopupWindow的宽高
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。 |
void |
update(int x,
int y)
在指定位置更新PopupWindow位置或大小等信息。
|
void |
update(int x,
int y,
float width,
float height)
在指定位置更新PopupWindow位置或大小等信息。
|
void |
update(View anchorView)
参考anchorView更新PopupWindow位置或大小等信息。
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonCreateContentViewpublic static int DEFAULT_BACKGROUND_COLOR
public static boolean DEBUG
public static final int MATCH_PARENT
public static final int WRAP_CONTENT
public BasePopupWindow(Context context)
public BasePopupWindow(Context context, boolean delayInit)
context - delayInit - 如果是true,请务必在您初始化后调用delayInit()public BasePopupWindow(Context context, int width, int height)
public BasePopupWindow(Context context, int width, int height, boolean delayInit)
context - width - height - delayInit - 如果是true,请务必在您初始化后调用delayInit()public void delayInit()
protected Animation onCreateShowAnimation()
该方法决定您的PopupWindow将会以怎样的动画展示出来,可以返回为 null
本类提供一些简单的动画方法:
getDefaultAlphaAnimation():得到一个默认进入的渐变动画getDefaultScaleAnimation():得到一个默认的放大缩小动画getTranslateVerticalAnimation(float, float, int) ()}:快速获取垂直方向的动画
如果需要用到属性动画,请覆写onCreateShowAnimator()
protected Animation onCreateDismissAnimation()
该方法决定您的PopupWindow将会以怎样的动画消失,可以返回为 null
如果返回不为空,则在返回动画播放结束后触发PopupWindow.dismiss()
本类提供一些简单的动画方法:
getDefaultAlphaAnimation(boolean) ()}:得到一个默认进入的渐变动画getDefaultScaleAnimation(boolean) ()}:得到一个默认的放大缩小动画getTranslateVerticalAnimation(float, float, int) ()}:快速获取垂直方向的动画
如果需要用到属性动画,请覆写onCreateDismissAnimator() ()}
protected Animator onCreateShowAnimator()
该方法决定您的PopupWindow将会以怎样的动画展示出来(返回 Animator),可以返回为 null
功能详情请看onCreateShowAnimation()
protected View onCreateAnimateView()
通过该方法您可以指定您的PopupWindow显示动画用于哪个View(onCreateShowAnimation()/onCreateShowAnimator())
可以返回为空 null
protected Animator onCreateDismissAnimator()
该方法决定您的PopupWindow将会以怎样的动画消失(返回 Animator),可以返回为 null
功能详情请看onCreateDismissAnimation() ()}
public BasePopupWindow setPopupFadeEnable(boolean isPopupFadeAnimate)
当传入true,你的PopupWindow将会淡入显示,淡出消失。
与onCreateShowAnimation()/onCreateDismissAnimation()不同的是,该方法为Window层级服务,固定Style
isPopupFadeAnimate - true for apply anim stylepublic boolean isPopupFadeEnable()
当前PopupWindow是否设置了淡入淡出效果
public BasePopupWindow setPopupAnimationStyle(int animationStyleRes)
设置PopupWindow的动画style针对PopupWindow整体的Window哦
通常情况下,请使用onCreateDismissAnimation() or onCreateShowAnimator()
public void showPopupWindow()
调用这个方法时,将会展示PopupWindow。
如果onCreateShowAnimation() or onCreateShowAnimator()其中之一返回不为空,
则在PopupWindow展示后为onCreateAnimateView() 指定的View执行动画
您可以在Activity.onCreate(Bundle)里面使用该方法,本方法在无法展示时会重试3次,如果3次都无法展示,则失败。
public void showPopupWindow(int anchorViewResid)
传入anchorView的ViewId,方法详情showPopupWindow(View)
anchorViewResid - anchorView的ViewIdpublic void showPopupWindow(View anchorView)
调用这个方法时,将会展示PopupWindow。
showPopupWindow()
anchorView - 锚点View,PopupWindow将会显示在其下方public void showPopupWindow(int x,
int y)
调用这个方法时,将会在指定位置弹出PopupWindow。
其他方法详情参考showPopupWindow()
x - 坐标轴xy - 坐标轴ypublic void update()
啥都不干,单纯的update,简单的说,就是更新你所设置的所有东西~
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。
public void update(View anchorView)
参考anchorView更新PopupWindow位置或大小等信息。
该方法跟anchorView关联,即您的gravity,offset等会跟随anchorView变化而变化
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。
anchorView - 被参考的anchorViewpublic void update(int x,
int y)
在指定位置更新PopupWindow位置或大小等信息。
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。
x - 目标位置x坐标y - 目标位置y坐标public void update(float width,
float height)
更新PopupWindow的宽高
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。
WARN:非常不建议在连续update的情况下使用背景模糊,这会导致较大的性能消耗。
width - 宽度height - 高度public void update(int x,
int y,
float width,
float height)
在指定位置更新PopupWindow位置或大小等信息。
x - 目标位置x坐标y - 目标位置y坐标width - 宽度height - 高度protected View onFindDecorView(Activity activity)
public BasePopupWindow setAdjustInputMethod(boolean needAdjust)
PopupWindow是否需要自适应输入法,为输入法弹出让出区域
needAdjust - public BasePopupWindow setAdjustInputMethod(boolean needAdjust, int flag)
PopupWindow是否需要自适应输入法,为输入法弹出让出区域
needAdjust - flag - The desired mode, see
WindowManager.LayoutParams.softInputMode
for the full listpublic BasePopupWindow setAutoShowInputMethod(EditText editText, boolean autoShow)
PopupWindow在展示的时候自动打开输入法,在传入参数时请务必传入EditText
public BasePopupWindow setSoftInputMode(int softInputMode)
softInputMode - The desired mode, see
WindowManager.LayoutParams.softInputMode
for the full listpublic BasePopupWindow setBackPressEnable(boolean backPressEnable)
禁止PopupWindow返回键dismiss
public View createPopupById(int layoutId)
这个方法封装了LayoutInflater.from(context).inflate,方便您设置PopupWindow所用的xml
layoutId - reference of layoutpublic <T extends View> T findViewById(int id)
还在用View.findViewById么,,,不如试试这款?
id - the ID to search fornull otherwisepublic BasePopupWindow setPopupWindowFullScreen(boolean isFullScreen)
允许PopupWindow覆盖屏幕(包含状态栏)
public BasePopupWindow setBackgroundColor(int color)
设置PopupWindow背景颜色,默认颜色为#8f000000
color - 背景颜色public BasePopupWindow setBackground(int drawableIds)
设置PopupWindow背景Drawable,默认颜色为#8f000000
drawableIds - 背景Drawable idpublic BasePopupWindow setBackground(Drawable background)
设置PopupWindow背景Drawable,默认颜色为#8f000000
background - 背景Drawablepublic BasePopupWindow setBackgroundView(View backgroundView)
设置PopupWindow背景View,因为背景全屏的原因,该View将会被强制设为MATCH_PARENT/MATCH_PARENT
backgroundView - 背景Viewpublic Drawable getPopupBackground()
获取当前PopupWindow背景
public BasePopupWindow setBlurBackgroundEnable(boolean blurBackgroundEnable)
设置PopupWindow弹出时是否模糊背景。
在使用模糊背景前,您可以通过setBlurOption(PopupBlurOption)传入模糊配置。
本方法默认模糊当前Activity的DecorView
blurBackgroundEnable - true for blur decorViewpublic BasePopupWindow setBlurBackgroundEnable(boolean blurBackgroundEnable, BasePopupWindow.OnBlurOptionInitListener optionInitListener)
设置PopupWindow弹出时是否模糊背景。
在使用模糊背景前,您可以通过setBlurOption(PopupBlurOption)传入模糊配置。
本方法允许您传入一个初始化监听,您可以在BasePopupWindow.OnBlurOptionInitListener.onCreateBlurOption(PopupBlurOption)中进行展示前的最后一次修改
blurBackgroundEnable - true for blur decorViewoptionInitListener - 初始化回调public BasePopupWindow setBlurOption(PopupBlurOption option)
应用模糊配置,更多详情请参考setBlurBackgroundEnable(boolean)或者setBlurBackgroundEnable(boolean, OnBlurOptionInitListener)
option - 模糊配置protected void setViewClickListener(View.OnClickListener listener, View... views)
public boolean isShowing()
public BasePopupWindow.OnDismissListener getOnDismissListener()
public BasePopupWindow setOnDismissListener(BasePopupWindow.OnDismissListener onDismissListener)
设置dismiss监听
onDismissListener - 监听器public BasePopupWindow.OnBeforeShowCallback getOnBeforeShowCallback()
public BasePopupWindow setOnBeforeShowCallback(BasePopupWindow.OnBeforeShowCallback mOnBeforeShowCallback)
mOnBeforeShowCallback - BasePopupWindow.OnBeforeShowCallback.onBeforeShow(View, View, boolean)public BasePopupWindow setShowAnimation(Animation showAnimation)
设置展示PopupWindow的动画,详情参考onCreateShowAnimation()
showAnimation - 展示动画public Animation getShowAnimation()
public BasePopupWindow setShowAnimator(Animator showAnimator)
设置展示PopupWindow的动画,详情参考onCreateShowAnimator()
showAnimator - 展示动画public Animator getShowAnimator()
public BasePopupWindow setDismissAnimation(Animation dismissAnimation)
设置退出PopupWindow的动画,详情参考onCreateDismissAnimation()
dismissAnimation - 退出动画public Animation getDismissAnimation()
public BasePopupWindow setDismissAnimator(Animator dismissAnimator)
设置退出PopupWindow的动画,详情参考onCreateDismissAnimator()
dismissAnimator - 退出动画public Animator getDismissAnimator()
public Activity getContext()
获取context,请留意是否为空null
nullpublic View getContentView()
获取PopupWindow的根布局
#onCreateContentView(),该布局在这里初始化。public View getDisplayAnimateView()
public PopupWindow getPopupWindow()
public int getOffsetX()
public BasePopupWindow setOffsetX(int offsetX)
offsetX - public int getOffsetY()
public BasePopupWindow setOffsetY(int offsetY)
offsetY - public int getPopupGravity()
public BasePopupWindow setPopupGravity(int popupGravity)
设置参考方向 Gravity
showPopupWindow()showPopupWindow(View)popupGravity - public BasePopupWindow setPopupGravity(BasePopupWindow.GravityMode mode, int popupGravity)
设置参考方向 Gravity
showPopupWindow()showPopupWindow(View)mode - popupGravity - public boolean isAutoLocatePopup()
public BasePopupWindow setAutoLocatePopup(boolean isAutoLocatePopup)
是否自动设置PopupWindow位置
在设定了clipToScreen的情况下setClipToScreen(boolean)
如果当前屏幕不足以完整显示您的PopupWindow,则PopupWindow会自行布置在其镜像位置。
比如当前PopupWindow显示在某个View的下方,而屏幕下方不够位置展示完整改PopupWindow, 当本设置为true,PopupWindow将会显示在原来的View的上方以满足完整显示PopupWindow的情况。
setOffsetY(int),则对应的偏移量也是在其适配后的位置生效
isAutoLocatePopup - 是否自适配public int getHeight()
获取PoupWindow的高度。
当PopupWindow没show出来的时候高度会是0,此时则返回pre measure的高度,不一定精准
public int getWidth()
获取PoupWindow的宽度。
当popupwindow没show出来的时候高度会是0,此时则返回pre measure的宽度,不一定精准
@Deprecated public BasePopupWindow setAllowDismissWhenTouchOutside(boolean dismissWhenTouchOutside)
setOutSideDismiss(boolean) instead是否允许点击PopupWindow外部时触发dismiss
dismissWhenTouchOutside - true for allowpublic BasePopupWindow setOutSideDismiss(boolean outSideDismiss)
是否允许点击PopupWindow外部时触发dismiss
outSideDismiss - true for allow@Deprecated public BasePopupWindow setAllowInterceptTouchEvent(boolean touchable)
setOutSideTouchable(boolean) instead
是否允许点击PopupWindow拦截事件。
如果允许拦截事件,则PopupWindow外部无法响应事件。
touchable - public BasePopupWindow setOutSideTouchable(boolean touchable)
是否允许点击PopupWindow拦截事件。
如果允许拦截事件,则PopupWindow外部无法响应事件。
touchable - public BasePopupWindow setClipChildren(boolean clipChildren)
clipChildren - 默认为truepublic BasePopupWindow setClipToScreen(boolean clipToScreen)
如果contentView的宽高大于屏幕宽高,因自动调整,可能会导致setAutoLocatePopup(boolean)失效
clipToScreen - 默认为truepublic boolean isAllowDismissWhenTouchOutside()
@Deprecated public boolean isAllowInterceptTouchEvent()
isOutSideTouchable()public boolean isOutSideTouchable()
public BasePopupWindow setAlignBackground(boolean isAlignBackground)
设置PopupWindow的背景是否对齐到PopupWindow。
默认情况下,PopupWindow背景都是铺满整个屏幕的。
但在某些情况下您可能在PopupWindow之上不需要展示背景,这时候您可以调用这个方法来强制Background对齐到PopupWindow的顶部。
isAlignBackground - 是否对齐背景public BasePopupWindow setAlignBackgroundGravity(int gravity)
设置PopupWindow的背景对齐PopupWindow的方式,请传入Gravity中的值
gravity - 请传入Gravity中的值,传入Gravity.NO_GRAVITY则意味着不对齐public BasePopupWindow linkTo(View anchorView)
允许PopupWindow跟某个anchorView关联,其位置,可视性将会跟anchorView同步>
WARN:非常不建议在anchorView频繁变化的情况下使用背景模糊,这会导致较大的性能消耗。
public BasePopupWindow setWidth(int width)
public BasePopupWindow setHeight(int height)
public BasePopupWindow setMaxWidth(int maxWidth)
public BasePopupWindow setMaxHeight(int maxHeight)
public BasePopupWindow setMinWidth(int minWidth)
public BasePopupWindow setMinHeight(int minHeight)
public BasePopupWindow setKeepSize(boolean keepSize)
在setClipToScreen(boolean)为true的情况下,BasePopup会针对剩余高度来调整Popup的大小,因此可能出现实际显示高度过小的情况
该方法可以保持默认测量高度从而阻止BasePopup的自动调整
public BasePopupWindow attachLifeCycle(Object owner)
public BasePopupWindow removeLifeCycle(Object owner)
public <P extends BasePopupWindow> BasePopupWindow setEventInterceptor(PopupWindowEventInterceptor<P> eventInterceptor)
eventInterceptor - public void dismiss()
public void dismiss(boolean animateDismiss)
animateDismiss - 传入为true,则执行退出动画后dismiss(如果有的话)public boolean onBeforeDismiss()
public boolean callDismissAtOnce()
public void dismissWithOutAnimate()
public boolean onDispatchKeyEvent(KeyEvent event)
event - public boolean onInterceptTouchEvent(MotionEvent event)
event - public boolean onTouchEvent(MotionEvent event)
event - public boolean onBackPressed()
public boolean onOutSideTouch()
protected Animation getTranslateVerticalAnimation(int start, int end, int durationMillis)
durationMillis - 动画显示时间start - 初始百分比end - 结束百分比protected Animation getTranslateVerticalAnimation(float start, float end, int durationMillis)
durationMillis - 动画显示时间start - 初始百分比(0f~1f)end - 结束百分比(0f~1f)protected Animation getScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
time=300
protected Animation getDefaultScaleAnimation()
protected Animation getDefaultScaleAnimation(boolean in)
in - true for scale inprotected Animation getDefaultAlphaAnimation()
protected Animation getDefaultAlphaAnimation(boolean in)
in - true for alpha inprotected AnimatorSet getDefaultSlideFromBottomAnimationSet()
public int getScreenHeight()
public int getScreenWidth()
public void onAnchorTop()
public void onAnchorBottom()
@Deprecated public void onAnchorTop(View mPopupView, View anchorView)
mPopupView - BasePopup.onCreateContentView()返回的ViewanchorView - showPopupWindow(View)传入的ViewonAnchorTop()@Deprecated public void onAnchorBottom(View mPopupView, View anchorView)
mPopupView - BasePopup.onCreateContentView()返回的ViewanchorView - showPopupWindow(View)传入的ViewonAnchorBottom()public void onDismiss()
onDismiss 在接口中 PopupWindow.OnDismissListenerprotected float dipToPx(float dip)
public static void setDebugMode(boolean debugMode)