弹窗

AlertDialog 

        AlertDialog.Builder builder = new AlertDialog.Builder(DeviceInfoActivity.this);
        builder.setTitle("重启");
        builder.setMessage("是否确认重启");
        builder.setPositiveButton("重启", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                // 重启
                present.sendOrder(cid, "97");
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.create().show();

BottomSheetDialog底部弹窗 

View view = LayoutInflater.from(this).inflate(R.layout.dialog_reboot, null);
BottomSheetDialog dialog = new BottomSheetDialog(this);
dialog.setContentView(view);
// 设置透明背景
dialog.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);
// show
dialog.show();

popupwindow

public class BasePopupWindow extends PopupWindow {

    private Window window;
    private boolean isTransparent = false;
    protected Context context;

    public BasePopupWindow(Context context) {
        super(context);
        this.context = context;
        if (context instanceof Activity) {
            this.window = ((Activity) context).getWindow();
        }
        popupwindowSetting();
    }

    private void popupwindowSetting() {
        setFocusable(true); // 设置PopupWindow可获得焦点
        setTouchable(true); // 设置PopupWindow可触摸
        setOutsideTouchable(false); // 设置非PopupWindow区域可触摸
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // 无背景
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    /**
     * 背景是否透明, 默认半透明
     *
     * @param isTransparent
     */
    public void setWindowTransparent(boolean isTransparent) {
        this.isTransparent = isTransparent;
    }

    // 设置背景透明度
    private void popOutShadow(PopupWindow popupWindow) {
        if (window == null && isTransparent) {
            return;
        }
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.alpha = 0.7f;
        window.setAttributes(lp);
        popupWindow.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = window.getAttributes();
                lp.alpha = 1f;
                window.setAttributes(lp);
            }
        });
    }
}

public class StatusPopupWindow extends BasePopupWindow {
    private View contentView;
    private String[] statusData = {"全部", "在线", "离线"};
    private Callback mCallback;

    public StatusPopupWindow(Context context) {
        super(context);
        contentView = LayoutInflater.from(context).inflate(R.layout.view_recyclerview, null);
        setContentView(contentView);
        setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        initView(context);
    }

    public void setCallback(Callback callback) {
        this.mCallback = callback;
    }

    private void initView(Context context) {
        // animation
        setAnimationStyle(R.style.PopupAnimation);
        // set
        RecyclerView recyclerView = contentView.findViewById(R.id.recyclerview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        StatusAdapter adapter = new StatusAdapter(context, statusData);
        recyclerView.setAdapter(adapter);
        // listener
        adapter.setOnItemClicksListener(new OnItemClicksListener() {
            @Override
            public void onItemClick(View view, int position) {
                dismiss();
                if (mCallback != null) {
                    mCallback.callback(statusData[position], position);
                }
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });
    }
}
public interface Callback {
    void callback(String str, int position);
}
    

// ---------------------------------------------------------------------
private void showUpgradePopupWindow(View parentView) {
        // view
        View view = LayoutInflater.from(context).inflate(R.layout.view_camera, null);
        upgradePopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        // 点击外部消失
        upgradePopupWindow.setBackgroundDrawable(new BitmapDrawable());
        upgradePopupWindow.setOutsideTouchable(true);
        // bg
        backgroundAlpha(0.9f);
        upgradePopupWindow.setOnDismissListener(new popupDismissListener());
        // position
        upgradePopupWindow.showAtLocation(parentView, Gravity.CENTER, 0, 0);
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getWindow().setAttributes(lp);
    }

    /**
     * 添加新笔记时弹出的popWin关闭的事件,主要是为了将背景透明度改回来
     */
    public class popupDismissListener implements PopupWindow.OnDismissListener {
        @Override
        public void onDismiss() {
            backgroundAlpha(1f);
        }
    }

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值