Android popupWindow 底部弹窗

这最近刚好写了一个点击分享,弹窗,然后点击各个按钮可以实现点击事件,下面就来分享一下.

 

弹窗的布局文件,有报错就是图片文件了,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rl_profile_share_mask"
    android:background="@color/mask_50">

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="101dp"
        android:background="@color/white"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/iv_profile_video_share_wechat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/res_btn_wx_pressed" />

        <ImageView
            android:id="@+id/iv_profile_video_share_wechatfriend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/res_btn_share_friends" />

        <ImageView
            android:id="@+id/iv_profile_video_share_qq"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/res_btn_qq_pressed" />
    </LinearLayout>
</RelativeLayout>

 

调用弹窗的方法

//分享框弹出
    public void showPopupwindow(){
        View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_profile_video_share_popupwindow, null);
        popupWindow = new PopupWindow(inflate, RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        //设置背景,这个没什么效果,不添加会报错
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        //设置点击弹窗外隐藏自身
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        //设置位置
        popupWindow.showAtLocation(inflate, Gravity.BOTTOM, 0, 0);
        //设置PopupWindow的View点击事件
        setOnPopupViewClick(inflate);
    }

    //分享点击事件
    private void setOnPopupViewClick(View view) {
        RelativeLayout rlShareMask = view.findViewById(R.id.rl_profile_share_mask);
        ImageView ivShareWechat = view.findViewById(R.id.iv_profile_video_share_wechat);
        ImageView ivShareWechatFriend = view.findViewById(R.id.iv_profile_video_share_wechatfriend);
        ImageView ivShareQq = view.findViewById(R.id.iv_profile_video_share_qq);
        rlShareMask.setOnClickListener(new View.OnClickListener() {//外部透明层
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        ivShareWechat.setOnClickListener(new View.OnClickListener() {//微信
            @Override
            public void onClick(View v) {
                ToastUtil.showCenterToast("微信");
                popupWindow.dismiss();
            }
        });
        ivShareWechatFriend.setOnClickListener(new View.OnClickListener() {//朋友圈
            @Override
            public void onClick(View v) {
                ToastUtil.showCenterToast("微信朋友圈");
                popupWindow.dismiss();
            }
        });
        ivShareQq.setOnClickListener(new View.OnClickListener() {//QQ
            @Override
            public void onClick(View v) {
                ToastUtil.showCenterToast("QQ");
                popupWindow.dismiss();
            }
        });
    }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值