android-使用Popupwindow

2022-07-30,

PopWindwos弹窗

 

private fun showStockPickPopupWindow(context: Context?, currentView: View, data: FStockPickerIndexEntity) {
        if (mLongPressSelectPopupWindow != null && mLongPressSelectPopupWindow!!.isShowing) {
            return
        }
        val rootView = LayoutInflater.from(context).inflate(R.layout.popupwindow_stock_pick, null)
        val tv_change_index = rootView.findViewById<TextView>(R.id.tv_change_index)
        val tv_change_name = rootView.findViewById<View>(R.id.tv_change_name)
        val tv_delete = rootView.findViewById<TextView>(R.id.tv_delete)
        tv_change_index.setOnClickListener {
            ToastHelper.toastLong("修改指标")
            FLaunchHelper.launchToStockPicker(mActivity)
            mLongPressSelectPopupWindow!!.dismiss()
        }
        tv_change_name.setOnClickListener {
            ToastHelper.toastLong("重命名")
            mLongPressSelectPopupWindow!!.dismiss()
            showChangeNameDialog(data)
        }
        tv_delete.setOnClickListener {
            ToastHelper.toastLong("删除")
            deleteStock(data)
            mLongPressSelectPopupWindow!!.dismiss()
        }

        mLongPressSelectPopupWindow = PopupWindow(rootView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        mLongPressSelectPopupWindow!!.isOutsideTouchable = true
        mLongPressSelectPopupWindow!!.isFocusable = true
        mLongPressSelectPopupWindow!!.setBackgroundDrawable(ColorDrawable())
        mLongPressSelectPopupWindow!!.isClippingEnabled = false
        mLongPressSelectPopupWindow!!.setOnDismissListener { }
        mLongPressSelectPopupWindow!!.showAsDropDown(currentView, AutoSizeUtils.pt2px(context, 518f), -(currentView.height - AutoSizeUtils.pt2px(context, 72f)))


        val lp = this.window.attributes
        lp.alpha = 0.3f
        this.window.attributes = lp

        mLongPressSelectPopupWindow?.setOnDismissListener(object : PopupWindow.OnDismissListener {
            override fun onDismiss() {
                lp.alpha = 1.0f
                window.attributes = lp
            }
        })
    }

 

本文地址:https://blog.csdn.net/mlsnatalie/article/details/108128500

《android-使用Popupwindow.doc》

下载本文的Word格式文档,以方便收藏与打印。