检查是否使用windowmanager显示视图

Ale*_*nez 1 android overlay android-windowmanager

在添加WindowManager之前,如何知道是否显示视图?我需要在原生拨号器中放置一个叠加层,但有时将原生拨号器放在mi自定义视图上方,我通过使用WindowManager多次添加元素来解决这个问题,但有时候视图会显示两次.

谢谢!!

private void callStartIncomingCallScreen(Context context, String incomingNumber) {
    startIncomingCallScreen(context, incomingNumber);

    Timer timer = new Timer();

    for (int i = 0; i < 2; i++) {
        timer.schedule(new StartIncomingCallScreenTimerTask(context, incomingNumber), 100 * i);
    }
}


class StartIncomingCallScreenTimerTask extends TimerTask {

    private Context context;
    private String incomingNumber;

    StartIncomingCallScreenTimerTask(Context context, String incomingNumber) {
        this.context = context;
        this.incomingNumber = incomingNumber;
    }

    public void run() {
        Intent intent = new Intent(context, IncomingCallGuiService.class);
        context.startService(intent);
    }
}
Run Code Online (Sandbox Code Playgroud)

在IncomingCallGuiService中,我添加如下视图:

final LayoutParams params = new LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
      LayoutParams.TYPE_SYSTEM_ALERT,
      LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCH_MODAL,
      PixelFormat.TRANSLUCENT);



WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
// add the overlay
wm.addView(view, params);
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以使用充气视图进行检查.你可以view.isShow()用来检查它.当您windowManager.addView(yourView)在调用时添加带有此返回true 的视图时isShow().

希望它能帮到你.