弹出PopWindow【自定义】【背景变暗并Pop取消时背景色还原】【弹出时Img图标不消失】

【自定义】

pop_version.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="right"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="144dp"
        android:layout_height="69dp"
        android:layout_marginTop="45dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/cab_button_white"
        android:orientation="vertical">

        <TextView
            android:layout_width="113dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="17dp"
            android:text="版本号:"
            android:textColor="@color/textBlack"
            android:textSize="@dimen/text_color_12" />

        <TextView
            android:id="@+id/tv_version"
            android:layout_width="113dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="v1.0 (11011028)"
            android:textColor="@color/textBlack"
            android:textSize="@dimen/text_color_12" />
    </LinearLayout>
</LinearLayout>

 drawable下 cab_button_white.xml

<!-- Style for "1" --><!-- Add this snippet to layer-list xml in drawable. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/textWhite" />
    <corners android:radius="8dp" />
</shape>

【背景变暗并Pop取消时背景色还原】

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.7f;
getWindow().setAttributes(lp);
mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

    @Override
    public void onDismiss() {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 1f;
        getWindow().setAttributes(lp);
    }
});

【 ActivityPopWindow所有显示】:

    private void PopLogVersion() {
        View mView = LayoutInflater.from(this).inflate(R.layout.pop_version, null, false);

        PopupWindow mPopupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        //PopWindow弹出时,图标不消失
        mPopupWindow.setFocusable(true);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.showAtLocation(mView, Gravity.TOP | Gravity.RIGHT, 0, 0);

        //设置PopWindow背景颜色。
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.7f;
        getWindow().setAttributes(lp);

        //给Pop设置监听,取消Popt弹出时的背景颜色。
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值