【问题标题】:Add a popup dialog over the call screen在通话屏幕上添加弹出对话框
【发布时间】:2014-12-07 11:18:50
【问题描述】:

如何在通话屏幕上添加弹出对话框?我将使用BroadcastReceiver 来监听来电并显示出来。我需要一个关于如何编写一个允许在来电上进行对话的活动的想法。另外,如何使对话框可移动到屏幕的任何部分?我已经实现了BroadcastRceiver 并执行了其他功能,所以我可以使用一个意图并从这个BroadcastRceiver 开始活动

【问题讨论】:

    标签: java android


    【解决方案1】:

    启动一个活动,然后使用该活动中的 AlertDialog Builder 来提示一个对话框

    设置自定义视图以自定义对话框外观

    【讨论】:

    • 如何使对话框在通话屏幕上移动?而且我还想通过将其拖出屏幕来取消它。
    • 你可以参考这个线程关于创建模态覆盖stackoverflow.com/questions/4481226/…
    • 感谢您的帮助。但是如何使它可以浮动,以便我可以将它拖动到屏幕上的任何位置?
    • 在屏幕上创建系统覆盖后,您可以在布局容器(而不是按钮)上设置 OnTouchListener。查看onTouch()中的action,看是MotionEvent.ACTION_DOWN、ACTION_MOVE还是ACTION_UP,判断系统覆盖的xy
    • 你能举个例子吗?我无法围绕一个只有一个对话框的活动。它会使用什么样的 XML 布局?不着急。
    【解决方案2】:

    试试这个

      AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
                LayoutInflater inflater = LayoutInflater.from(context);
                View dialogView = inflater.inflate(R.layout.caller_dialog, null);
    
                ImageView button = dialogView.findViewById(R.id.close_btn);
                builder.setView(dialogView);
                final AlertDialog alert = builder.create();
                alert.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                alert.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
                alert.setCanceledOnTouchOutside(true);
                alert.show();
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                Window window = alert.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
                window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                window.setGravity(Gravity.TOP);
                lp.copyFrom(window.getAttributes());
                //This makes the dialog take up the full width
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                window.setAttributes(lp);
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //close the service and remove the from from the window
                        alert.dismiss();
                    }
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-08
      • 2023-01-17
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 2015-02-13
      相关资源
      最近更新 更多