直播商城原始碼,PopupWindow選單在ListView中顯示

zhibo系統開發發表於2023-04-25

直播商城原始碼,PopupWindow選單在ListView中顯示

    private PopupWindow mOperaPopup;
    private void showMenuPopup(View anchor)
    {
        if(mOperaPopup==null)
        {
            View popupView=View.inflate(mContext,R.layout.popup_opera_subject,null);
            mOperaPopup=new PopupWindow(mContext);
            mOperaPopup.setBackgroundDrawable(new ColorDrawable(
                    mContext.getResources().getColor(R.color.transparent)));
            mOperaPopup.setContentView(popupView);
            mOperaPopup.setFocusable(true);
            mOperaPopup.setOutsideTouchable(true);
            //ppw訊息監聽,讓整體背景恢復到正常
            mOperaPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    WindowManager.LayoutParams layoutParams=mActivity.getWindow().getAttributes();
                    layoutParams.alpha=1.0f;
                    mActivity.getWindow().setAttributes(layoutParams);
                }
            });
            //手機返回鍵監聽,讓ppw消失
            popupView.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        mOperaPopup.dismiss();
                        return true;
                    }
                    return false;
                }
            });
        }
        int offX=ScreenInfomationLoader.getInstance().dpToPx(107);//適配自定義偏移距離(根據具體佈局)
        //gravity是表示ppw相對於anchor的左邊距還是右邊距,x方向向右為正,y方法,向下為正
        mOperaPopup.showAsDropDown(anchor,-offX,0,Gravity.LEFT);
        WindowManager.LayoutParams layoutParams=mActivity.getWindow().getAttributes();
        layoutParams.alpha=0.8f;//透過透明度控制整體背景變暗,值越大,越透明;值越小,越暗。
        mActivity.getWindow().setAttributes(layoutParams);
    }

以上就是 直播商城原始碼,PopupWindow選單在ListView中顯示,更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2948646/,如需轉載,請註明出處,否則將追究法律責任。

相關文章