亲测可用.
public abstract class BottomPushPopupWindow extends PopupWindow {

protected Context context;private WindowManager wm;private View maskView;@SuppressWarnings("deprecation")public BottomPushPopupWindow(Context context, T t) {    super(context);    this.context = context;    wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);    initType();    setContentView(generateCustomView(t));    setWidth(ViewGroup.LayoutParams.MATCH_PARENT);    setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);    setOutsideTouchable(true);    setFocusable(true);    setBackgroundDrawable(context.getResources().getDrawable(android.R.color.transparent));    setAnimationStyle(R.style.Animations_BottomPush);}protected abstract View generateCustomView(T t);@TargetApi(23)private void initType() {    setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);}@Overridepublic void showAtLocation(View parent, int gravity, int x, int y) {    addMaskView(parent.getWindowToken());    super.showAtLocation(parent, gravity, x, y);}@Overridepublic void showAsDropDown(View anchor, int xoff, int yoff) {    addMaskView(anchor.getWindowToken());    super.showAsDropDown(anchor, xoff, yoff);}@Overridepublic void dismiss() {    removeMaskView();    super.dismiss();}/** * 显示在界面的底部 */public void show(Activity activity) {    showAtLocation(activity.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);}private void addMaskView(IBinder token) {    WindowManager.LayoutParams p = new WindowManager.LayoutParams();    p.width = WindowManager.LayoutParams.MATCH_PARENT;    p.height = WindowManager.LayoutParams.MATCH_PARENT;    p.format = PixelFormat.TRANSLUCENT;    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;    p.token = token;    p.windowAnimations = android.R.style.Animation_Toast;    maskView = new View(context);    maskView.setBackgroundColor(0x7f000000);    maskView.setFitsSystemWindows(false);    maskView.setOnKeyListener(new OnKeyListener() {        @Override        public boolean onKey(View v, int keyCode, KeyEvent event) {            if (keyCode == KeyEvent.KEYCODE_BACK) {                removeMaskView();                return true;            }            return false;        }    });    wm.addView(maskView, p);}private void removeMaskView() {    if (maskView != null) {        wm.removeViewImmediate(maskView);        maskView = null;    }}

}

更多相关文章

  1. Android(安卓)Activity界面切换添加动画特效
  2. Android(安卓)拨号器的简单实现
  3. android用户界面之按钮(Button)教程实例汇
  4. 锁屏界面
  5. Android(安卓)P SystemUI之StatusBar UI布局status_bar.xml解析
  6. android用户界面-组件Widget-地图视图MapView
  7. android用户界面-组件Widget-画廊视图Gallery
  8. Android中判断网络功能是否可用
  9. Android中使Dialog显示时背景不变暗

随机推荐

  1. Android(安卓)限制显示小数点位数
  2. Android与H5页面的互调
  3. 【Android(安卓)开发教程】纯编码实现UI
  4. 自定义控件和试图(部分原生api)下拉菜单
  5. android英语
  6. Android学习笔记12:框架布局管理器FrameLa
  7. Material Design详解 主题布局
  8. Android控制手机振动相关
  9. Android(安卓)清除所有Notification的一
  10. “layer-list” 和 “include”的使用