Chinese | English
- Simple and precise control of display position with Gravity and offset.
- Basepopup is an abstract class with almost no constraints on subclasses. You can customize your PopupWindow just like a custom View.
- Support Animation, Animator, freely control the animation of your PopupWindow, no longer need to write animation xml.
- Darkening the background, changing the background color will be very easy.
- Blur background or partial blur is also very easy.
- Backpress control , click outside to dismiss , outside touch event all separation,no longer have to worry about my PopupWindow various key events problems.
- We also support event delivery at the same time.
- Support linkTo anchorview.
- Support for chained calls. For a simple scene,try QuickPopupBuilder,I bet you will love it.
WARNING:
- Please be sure to read this README carefully. Please check the update log for each version upgrade, which can reduce unnecessary detours for you.
- Please pay attention on the dependence version, the Release version is a stable version, and Candy is a preview version.
- Release version: Generally published to Release after repeated verification of the Candy version. If you have higher stability requirements, please use the Release version.
- Candy version: new features, issue fixes will be published to the Candy version, Candy version is updated more frequently, but usually has new features, if you like to test new features and stability requirements are not high, please use the Candy version.
- Switching between Release and Candy versions may cause Build to fail. At this time, you can clean Project.
- If you are a previous 1.x user and want to update to 2.x now, please check before the update: 1.x migration to 2.x help documentation
Android P has been adapted, thanks to the method of @Guolei1130 collection.
Article address:android_p_no_sdkapi_support
See more:Wiki#Usage
Release | Candy |
---|---|
Add dependencies to Gradle (Please replace {$latestVersion} with the version shown in the Jcenter tab above)
dependencies {
implementation 'com.github.razerdp:BasePopup:{$latestVersion}'
//candy version
//implementation 'com.github.razerdp:BasePopup_Candy:{$latestVersion}'
}
Support blur background from 1.9.0-alpha(Just call:setBlurBackgroundEnable(boolean)
)
RenderScript minimum support api 17 (lower case will use fastblur),you need to configure the following code in gradle
defaultConfig {
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
}
Customize your PopupWindow layout just like you would normally customize a View layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/holo_blue_dark"
android:orientation="vertical"
>
<TextView
android:id="@+id/tx_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp"
android:text="test1"
android:textColor="@color/color_black1"/>
</LinearLayout>
public class DemoPopup extends BasePopupWindow {
public DemoPopup(Context context) {
super(context);
}
@Override
public View onCreateContentView() {
return null;
}
}
It is strongly recommended to use createPopupById()
in onCreateContentView()
to inflate view so that the library can correctly parse and adapt.
public class DemoPopup extends BasePopupWindow {
public DemoPopup(Context context) {
super(context);
}
// Must be implemented, return your contentView here
// recommended to use createPopupById() for inflate
@Override
public View onCreateContentView() {
return createPopupById(R.layout.popup_normal);
}
// The following are optional codes (not required)
// Return to the show and dismiss animations for PopupWindow. Basepopup provides several default animations, which can be freely implemented here.
@Override
protected Animation onCreateShowAnimation() {
return getDefaultScaleAnimation(true);
}
@Override
protected Animation onCreateDismissAnimation() {
return getDefaultScaleAnimation(false);
}
}
There are three ways to show PopupWindow:showPopupWindow()
,showPopupWindow(View anchor)
and showPopupWindow(int x, int y)
:
new DemoPopup(getContext()).showPopupWindow();
//new DemoPopup(getContext()).showPopupWindow(v);
//new DemoPopup(getContext()).showPopupWindow(x,y);
These three methods have different meanings:
showPopupWindow()
:No-params method,At this point, the PopupWindow reference object is the screen (or the entire DecorView).Gravity behaves just like the Gravity in FrameLayout, indicating which position it is on the screen.showPopupWindow(View anchor)
:Set an anchorView.At this point, the PopupWindow reference object is the incoming anchorView.The performance of Gravity means that this PopupWindow should be in the orientation of the target AnchorView.showPopupWindow(int x, int y)
:Set the position for razerdp.basepopup,At this point PopupWindow will pop up at the specified location.
Suggestion:If PopupWindow needs to repeat the display or retain state, it is recommended to be used as a member variable instead of being created as a local variable each time.
For more apis on Gravity, check out:Wiki-Api:Gravity
Sample for showPopupWindow()
:
showPopupWindow()
gravity = CENTER In the above example xml specifies layout_gravity=center |
gravity = RIGHT | CENTER_VERTICAL |
---|---|
showPopupWindow(View v)
gravity = CENTER In the above example xml specifies layout_gravity=center |
gravity = RIGHT | CENTER_VERTICAL |
---|---|
showPopupWindow(int x, int y)
gravity = CENTER In the above example xml specifies layout_gravity=center |
---|
QuickPopupBuilder supports chained calls to generate a PopupWindow based on QuickPopup.The Builder is designed to quickly build a simple PopupWindow that does not contain complex logic, such as the above case.Avoid creating too many BasePopupWindow implementation classes.
Attention:The PopupWindow animation in the default
QuickPopupBuilder.QuickPopupConfig
is zoomed out and disappears.
QuickPopupBuilder.with(getContext())
.contentView(R.layout.popup_normal)
.config(new QuickPopupConfig()
.gravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL)
.withClick(R.id.tx_1, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(), "clicked", Toast.LENGTH_LONG).show();
}
}))
.show();
//.show(anchorView);
show() | show(anchorView) |
---|---|
See more in wiki (continuous improvement)
Link👉WIKI
Update log (Historical update)
-
【Release】2.1.9(2019/03/07)
- Please see candy updateLog on under
-
【Candy】2.1.9
- 【Candy】2.1.9-prerelease(2019/03/07)
- Support layout in cutouts for Android P,fixed #154
- 【Candy】2.1.9-beta3(2019/03/1)
- fixed #152
- 【Candy】2.1.9-beta1(2019/02/28)
- optimized code,fix override AnimationListener for dismissAnimation
- 【Candy】2.1.9-beta(2019/2/26)
- add oom catcher for BlurHelper
- 【Candy】2.1.9-alpha4(2019/2/21)
- optimized background blur
- 【Candy】2.1.9-alpha3(2019/2/21)
- fixed alpha2
- 【Candy】2.1.9-alpha2(2019/2/19)
- Removed from lib's AndroidManifest,fixed #149
- 【Candy】2.1.9-alpha1(2019/02/18)
- Adapted DialogFragment,fixed #145
- 【Candy】2.1.9-prerelease(2019/03/07)
-
【Release】2.1.8(2019/01/26)
- This version update adds a lot of new features.
- Update details:
- Adapted to use ImmersionBar
- Repair of horizontal screen incompatibility problems
- Fix the problem that the constructor width is not valid
- Support for background masks without intercepting events. That black technology has changed to a more friendly way!
- Fix the problem that the virtual button is displayed together when the popup is displayed.
- QuickPopupConfig adds
dismissOnOutSideTouch()
method - Optimize QuickPopupBuilder, see more inWiki
- Optimize for problems with #138
- Fix the call order of
setAlignBackgroundGravity()
andsetAlignBackground()
-
【Candy】2.1.8
- 【Candy】2.1.8-prerelease2(2019/01/24)
- Adapted to use ImmersionBar
- 【Candy】2.1.8-prerelease(2019/01/23)
- Repair of horizontal screen incompatibility problems
- 【Candy】2.1.8-beta7(2019/01/22)
- Beta3 and beta4 and beta5 and beta6 were deleted~
- Fix beta2's problem with focusable, remove useless code
- Fix the problem that the constructor width is not valid
- Support for background masks without intercepting events. That black technology has changed to a more friendly way!
- 【Candy】2.1.8-beta2(2019/01/22)
- 【Candy】2.1.8-beta1(2019/01/21)
- 【Candy】2.1.8-alpha2(2019/01/18)
- Optimize QuickPopupBuilder, see more inWiki
- 【Candy】2.1.8-alpha(2019/01/17)
- Optimize for problems with #138
- Fix the call order of
setAlignBackgroundGravity()
andsetAlignBackground()
- 【Candy】2.1.8-prerelease2(2019/01/24)
-
【Release】2.1.7(2019/01/16)
- Fixed an issue where
onAnchorTop()
oronAnchorBottom()
was called multiple times duringsetAutoLocatePopup(true)
- Fixing 'setAllowInterceptTouchEvent(false)`, the problem of not being able to locate anchorView due to default restrictions
- Optimize the soft keyboard default offset calculation method
- Optimize keyboard height calculation method
- Thanks to [@ParfoisMeng] (https://github.com/ParfoisMeng) for finding the soft keyboard offset problem and submitting [PR#130] (https://github.com/razerdp/ BasePopup/pull/130)
- Fixed an issue where
-
【Candy】2.1.7-beta(2019/01/10~2019/01/13)
- Fixing 'setAllowInterceptTouchEvent(false)`, the problem of not being able to locate anchorView due to default restrictions
- Optimize the soft keyboard default offset calculation method
- Optimize keyboard height calculation method
GravityPopupFrag | LocatePopupFrag |
---|---|
AnyPosPopupFrag | UpdatePopupFrag |
BlurSlideFromBottomPopupFrag | CommentPopup |
SlideFromBottomPopup | InputPopup |
ListPopup | MenuPopup |
Ali-pay | |
---|---|
More Q&A:WIKI#Q&A
A:Call setBackgroundColor(Color.TRANSPARENT) or [setBackground](https://github.com /razerdp/BasePopup/wiki/API#setbackgroundint-drawableids)(0)
A:Call dismiss(false)
or dismissWithOutAnimate()
A:Call setAllowDismissWhenTouchOutside(false)
A:PopupWindow needs windowToken, so the ApplicationContext or Service can't be popped up. It is recommended to pop the popupwindow by event notification to the top of the stack.
ISSUE REF:#140
Google Issue Tracker:#36984016
A:The View in PopupWindow can't get WindowToken, and the paste function is also a PopupWindow. Its display must require WindowToken, so it can't be pasted.
A:Set setPopupWindowFullScreen(false)
A:Set setBackPressEnable(false)
A:When the root layout is match_parent, razerdp.basepopup will do some difference handling.
When you set setClipToScreen(true), if your root layout is match_parent
, then it means The maximum height of your layout is the screen height. If your root layout is wrap_content
, the maximum height may be higher than the screen height.
Such as full screen listview in demo
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" // 请留意这里
android:background="@android:color/white"
>
<ListView
android:id="@+id/popup_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/line_bg"
android:dividerHeight="0.5dp"
android:scrollbars="vertical"
/>
</RelativeLayout>
layout_height = match_parent | layout_height = wrap_content |
---|---|
Pay attention to the difference between the bottom of the listview of the two images, where the bottom of the wrap_content
has exceeded the bottom of the screen and cannot be displayed completely.