android从actionbar位置下方向滑出窗口PopupWindow

本文介绍了一种在Android应用中实现自定义弹出窗口的方法,包括如何创建视图、设置弹窗属性及显示位置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gif不是那么清晰委屈,凑合着看哈O(∩_∩)O

                                         

 //以下是如何实现自定义弹出窗口,mView就是你想要展现的视图
        View mView = LayoutInflater.from(this).inflate(R.layout.click_booth_floating, null);
        WindowManager wm = this.getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        //设置窗口的宽度
        mView.setMinimumWidth(width);
      /* 下面是对PopupWindow四个参数的详细介绍
       * @param contentView the popup's content
       * @param width the popup's width
       * @param height the popup's height
       * @param focusable true if the popup can be focused, false otherwise
       */
        PopupWindow popupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT , true);
        //获取AppBarLayout
        AppBarLayout appBar = (AppBarLayout) findViewById(R.id.map_activity_app_bar_layout);
        //点击popupwindow之外的地方,popupwindow消失
        popupWindow.setOutsideTouchable(true); 
        //由于Android 版本差异性,在不需要背景的情况下设置背景为透明
        popupWindow.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.map_page_background)));
        //从appbar位置向下滑出PopupWindow
        popupWindow.showAsDropDown(appBar); 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值