Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何让popwindow的上部不变暗,下部变暗 #27

Open
CharlesWWT opened this issue Apr 26, 2018 · 3 comments
Open

如何让popwindow的上部不变暗,下部变暗 #27

CharlesWWT opened this issue Apr 26, 2018 · 3 comments

Comments

@CharlesWWT
Copy link

比如我在中间弹出的popwindow,上下都变暗了,我只想让下部变暗
_20180426152153

@yecaler
Copy link

yecaler commented Apr 26, 2018

如果只想使用style设置,是没有办法的。
所以只能你写的时候给布局设置长一点,底部设置成你想要的透明度。也就是变暗。上面在style里面设置不变暗。

@CQBOBOZHU
Copy link

你可以加载的布局里面最下方添加一个半透明的view。但是这个方法在华为手机上会造成全屏效果。

@CQBOBOZHU
Copy link

public static void show(final PopupWindow popupWindow, final View view) {
//PopupWindowCompat.showAsDropDown(popupWindow, view, 0, 0, Gravity.NO_GRAVITY);
if (Build.VERSION.SDK_INT < 24) {
popupWindow.showAsDropDown(view);
} else if (Build.VERSION.SDK_INT == 24) {
// 适配 android 7.0
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
} else if (Build.VERSION.SDK_INT > 24) {
// 适配 android 7.1.1
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
final int offsetY = location[1] + view.getHeight();
Rect r = new Rect();
view.getRootView().getWindowVisibleDisplayFrame(r);
int screenHeight = (r.bottom - r.top + ScreenUtils.getStatusHeight(view.getContext()));
popupWindow.setHeight(screenHeight - offsetY);
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, offsetY);
view.getRootView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@OverRide
public void onGlobalLayout() {
Rect r = new Rect();
view.getRootView().getWindowVisibleDisplayFrame(r);
int screenHeight = (r.bottom - r.top + ScreenUtils.getStatusHeight(view.getContext()));
popupWindow.setHeight(screenHeight - offsetY);
popupWindow.update(0, offsetY, r.right - r.left, screenHeight - offsetY);
}
});
}
}
上面全面效果解决办法。 用这个。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants