Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t单击作为覆盖的视图下的按钮_Android_Overlay - Fatal编程技术网

Android Can';t单击作为覆盖的视图下的按钮

Android Can';t单击作为覆盖的视图下的按钮,android,overlay,Android,Overlay,我正在开发一个应用程序,它在屏幕上叠加了一个视图,作为屏幕上的一种色调。我已经得到了我想要的颜色的视图,我可以看到它后面的按钮。。问题是我无法单击它们!:( 以下是该应用程序在屏幕上实现的效果(这是我想要的外观): import android.app.Service; import android.content.Intent; import android.graphics.Color; import android.graphics.PixelFormat; import android.

我正在开发一个应用程序,它在屏幕上叠加了一个视图,作为屏幕上的一种色调。我已经得到了我想要的颜色的视图,我可以看到它后面的按钮。。问题是我无法单击它们!:(

以下是该应用程序在屏幕上实现的效果(这是我想要的外观):

import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class OverlayService extends Service {
    private WindowManager windowManager;
    private View filter;

    @Override
    public IBinder onBind(Intent intent) {
        // Not used
        return null;
    }

    @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    filter = new View(this); // Create a new view
    float alpha = (float) 0.8; // Create alpha variable
    filter.setAlpha(alpha); // Set alpha (this doesn't seem to do anything)
    filter.setBackgroundColor(Color.YELLOW); // Set the background colour to yellow
    filter.getBackground().setAlpha(80); // Set the background's alpha (this is the call that works!)

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(filter, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (filter != null) windowManager.removeView(filter); // If the filter exists, remove it
  }

}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, // This line changed!
        PixelFormat.TRANSLUCENT);

我的代码:

import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class OverlayService extends Service {
    private WindowManager windowManager;
    private View filter;

    @Override
    public IBinder onBind(Intent intent) {
        // Not used
        return null;
    }

    @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    filter = new View(this); // Create a new view
    float alpha = (float) 0.8; // Create alpha variable
    filter.setAlpha(alpha); // Set alpha (this doesn't seem to do anything)
    filter.setBackgroundColor(Color.YELLOW); // Set the background colour to yellow
    filter.getBackground().setAlpha(80); // Set the background's alpha (this is the call that works!)

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(filter, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (filter != null) windowManager.removeView(filter); // If the filter exists, remove it
  }

}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, // This line changed!
        PixelFormat.TRANSLUCENT);

干杯!

将WindowManager布局参数更改为:

import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class OverlayService extends Service {
    private WindowManager windowManager;
    private View filter;

    @Override
    public IBinder onBind(Intent intent) {
        // Not used
        return null;
    }

    @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    filter = new View(this); // Create a new view
    float alpha = (float) 0.8; // Create alpha variable
    filter.setAlpha(alpha); // Set alpha (this doesn't seem to do anything)
    filter.setBackgroundColor(Color.YELLOW); // Set the background colour to yellow
    filter.getBackground().setAlpha(80); // Set the background's alpha (this is the call that works!)

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(filter, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (filter != null) windowManager.removeView(filter); // If the filter exists, remove it
  }

}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, // This line changed!
        PixelFormat.TRANSLUCENT);

感谢@DeeV:)

将WindowManager布局参数更改为:

import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class OverlayService extends Service {
    private WindowManager windowManager;
    private View filter;

    @Override
    public IBinder onBind(Intent intent) {
        // Not used
        return null;
    }

    @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    filter = new View(this); // Create a new view
    float alpha = (float) 0.8; // Create alpha variable
    filter.setAlpha(alpha); // Set alpha (this doesn't seem to do anything)
    filter.setBackgroundColor(Color.YELLOW); // Set the background colour to yellow
    filter.getBackground().setAlpha(80); // Set the background's alpha (this is the call that works!)

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(filter, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (filter != null) windowManager.removeView(filter); // If the filter exists, remove it
  }

}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, // This line changed!
        PixelFormat.TRANSLUCENT);

多亏了@DeeV:)

我不确定,但是您是否已经尝试覆盖'onInterceptTouchEvent'以返回'filter'-视图的false?在layoutparams中,您应该包括“FLAG_not_TOUCHABLE”。@Aleksandrmedvedevev该视图(超类)没有名为
onInterceptTouchEvent
的方法@DeeV!非常感谢。这不起作用Marshmallow我不确定,但您是否已经尝试覆盖“onInterceptTouchEvent”以返回“filter”视图的false?在layoutparams中,您应该包括“FLAG\u not\u TOUCHABLE”。@AleksandrMedvedev视图(超类)没有名为
onInterceptTouchEvent
@DeeV brilliant fixed!非常感谢。这不适用于Marshmallow在我创建的新AVD上,覆盖右侧被切断,这是通过将第一个参数更改为
WindowManager.LayoutParams.MATCH\u PARENT
而不是
WindowManager.LayoutParams.WRAP\u CONTENT
来修复的。在新AVD上,我创建的覆盖右侧被切断,通过将第一个参数更改为
WindowManager.LayoutParams.MATCH_PARENT
而不是
WindowManager.LayoutParams.WRAP_CONTENT
,可以解决此问题。