【问题标题】:Android Error Window Causes Back Button to Stop WorkingAndroid 错误窗口导致返回按钮停止工作
【发布时间】:2015-11-26 04:13:28
【问题描述】:

我有一个应用程序应该覆盖通知栏并在触摸时执行操作..

现在,我设法通过创建一个系统覆盖按钮来使其工作:

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            statusBarHeight,
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.RIGHT | Gravity.TOP;

    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
    wm.addView(mView, params);

但是当我尝试点击设备后退按钮时它不起作用。

请注意,我无法将 TYPE_SYSTEM_ERROR 更改为 TYPE_SYSTEM_ALERT,因为它必须覆盖通知栏。

我也尝试添加标志 FLAG_NOT_FOCUSABLE.. 在这种情况下,后退按钮有效,但未调用 onTouchEvent。

【问题讨论】:

    标签: java android overlay android-windowmanager


    【解决方案1】:

    我做这个:

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
            mParams = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    Constant.NOTIFY_HEIGHT,
                    WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            mParams.gravity = Gravity.CENTER | Gravity.TOP;
    
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            mNotifyView = inflater.inflate(R.layout.notification_safety_count_down_layout, null);
            mNotifyTxt = (TextView) mNotifyView.findViewById(R.id.txt_notification_safety_count_down_time);
    
            mWindowManager.addView(mNotifyView, mParams);
    
            mNotifyView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    Intent intent = new Intent(SafetyCountDownService.this, DoroAssistanceAppActivity.class);
                    intent.putExtra(Constant.CALL_FROM, Constant.CALL_FROM_NOTIFICATION);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
    
                }
            });
    

    请试试!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2018-03-24
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      相关资源
      最近更新 更多