华为APP审核,权限说明弹窗

在这里插入图片描述
工具类

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;


/**
 * 自定义封装 PopupWindow 弹窗
 */
public class PermissionDialog {

    public PopupWindow PopupWindow(Activity mContext, View view, String title, String tips) {
        View inflater = LayoutInflater.from(mContext).inflate(R.layout.popup_permissions_layout, null);
        PopupWindow mPopupWindow = new PopupWindow(inflater, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setBackgroundDrawable(null);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setFocusable(true);
        mPopupWindow.setTouchable(true);
        // 设置背景颜色变暗
        WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
        lp.alpha = 0.7f;
        mContext.getWindow().setAttributes(lp);
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
                lp.alpha = 1f;
                mContext.getWindow().setAttributes(lp);
            }
        });

        TextView tv_title = inflater.findViewById(R.id.tv_title);
        tv_title.setText(title);
        TextView tv_tips = inflater.findViewById(R.id.tv_tips);
        tv_tips.setText(tips);

        mPopupWindow.showAtLocation(view, Gravity.TOP, 0, 0);

        return mPopupWindow;
    }

}

xml

<?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="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="15dp"
        android:layout_marginBottom="15dp"
        android:background="@drawable/shape_search_bg_white"
        android:orientation="vertical"
        android:padding="15dp">

        <TextView
            android:id="@+id/tv_title"
            style="@style/MainTextDarkBold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="相机、相册权限使用说明" />

        <TextView
            android:id="@+id/tv_tips"
            style="@style/MainTextDark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dp_10"
            android:text="用于更换头像" />

    </LinearLayout>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="18dp" />

    <solid android:color="@color/white" />

</shape>

使用

    @OnClick(R.id.tv_verify_report)
    void onVerifyClick(View view) {
        if (isUserLogin()) {
            if (ContextCompat.checkSelfPermission(Objects.requireNonNull(getContext()), Manifest.permission.CAMERA)
                    == PackageManager.PERMISSION_GRANTED) {
                ActivityUtils.startActivity(ReportVerifyActivity.class);
            } else {
                mPopupWindow = new PermissionDialog().PopupWindow(getBaseActivity(), view, "相机权限使用说明:", "用于扫描二维码获取报告");
                Disposable d = new RxPermissions(HomeFragment.this)
                        .request(Manifest.permission.CAMERA)
                        .subscribe(aBoolean -> {
                            if (mPopupWindow != null) {
                                mPopupWindow.dismiss();
                            }

                            if (aBoolean) {
                                ActivityUtils.startActivity(ReportVerifyActivity.class);
                            } else {
                                ToastUtils.showLong("报告验真需要开启摄像头权限");
                            }
                        });
            }
        }
    }
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值