PopWindow 遇到的坑


在工作遇到使用popwindow ,本以为挺简单的,写完就交给测试了,没想到在4.4oppo手机上出现 各种问题,

问题1:popwindow  被状态栏 遮盖住了一部分

        问题2:点击 Popwindow 外部区域 没有消失掉,我代码里可是加了设置的。

        问题3:弹出popwindow后 屏幕背景应该变暗,没有变暗。

       问题4:没有弹出动画效果

      



 private void showCustomerServicePop(final String hotline) {


        if (customerPopView == null) {

            LayoutInflater layoutInflater = (LayoutInflater) this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            customerPopView = layoutInflater.inflate(R.layout.pop_customer_service, null);
        }

        LinearLayout llUdeskService = (LinearLayout) customerPopView.findViewById(R.id.ll_custom_service_udesk);  
        LinearLayout llPhoneService = (LinearLayout) customerPopView.findViewById(R.id.ll_custom_service_phone);  //电话客服
        if (customerPopWindow == null) {
            customerPopWindow = new PopupWindow(customerPopView,
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        }
        //适配4.0-5.0版本的手机
//问题1
        ColorDrawable cd = new ColorDrawable(0xb2000000);//70%透明度
        customerPopWindow.setBackgroundDrawable(cd);
//问题2
        customerPopWindow.setTouchable(true);
        customerPopWindow.setOutsideTouchable(true);
        //popwindow弹出动画
//问题4
        customerPopWindow.setAnimationStyle(R.style.popwinow_anim_style);
        //设置各个控件的点击响应
        llUdeskService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开udesk
                openUdesk();
                customerPopWindow.dismiss();
            }
        });
        final String finalHotline = hotline.replaceAll("-", "");
        llPhoneService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MYAlertDialog dialog = new MYAlertDialog(mContext, MYAlertDialog.TYPE_BUTTON_TWO, "客服电话", hotline, "取消", "呼叫") {
                    @Override
                    public void clickCallBackRight() {
                        super.clickCallBackRight();
                        //拨打客服电话
                        Intent intent1 = new Intent();
                        intent1.setAction(Intent.ACTION_CALL);
                        intent1.setData(Uri.parse("tel:" + finalHotline));
                        startActivity(intent1);
                    }
                };
                dialog.setOnTouchOutsideClose(true);
                dialog.show();
                customerPopWindow.dismiss();
            }
        });

        //显示PopupWindow
        customerPopWindow.showAtLocation(this.getActivity().getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
//问题3
        //屏幕背景变化
        final WindowManager.LayoutParams lp = this.getActivity().getWindow().getAttributes();
        lp.alpha = 0.7f;
        final Window w = this.getActivity().getWindow();
        w.setAttributes(lp);
        customerPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                lp.alpha = 1;
                w.setAttributes(lp);
            }
        });

animation

    <style name="popwinow_anim_style">
        <item name="android:windowEnterAnimation">@anim/popwindow_open</item>
        <item name="android:windowExitAnimation">@anim/popwindow_close</item>
    </style>
open animation
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromYDelta="100%"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:toYDelta="0" />
close animation
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:toXDelta="0"
    android:toYDelta="100%" />



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值