今天遇到一个问题,WindowManager同时add两个view,后出来的view上面的按钮虽然通过requestFocus方法拿到了焦点,但实际焦点还在之前出来的view上,对比了两个view的WindowManager.LayoutParams参数设置,发现前一个view的flag参数为WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,后一个view的flag参数为WindowManager.LayoutParams.TYPE_PHONE,查了一下文档:
/**
* Window type: phone. These are non-application windows providing
* user interaction with the phone (in particular incoming calls).
* These windows are normally placed above all applications, but behind
* the status bar.
* In multiuser systems shows on all users' windows.
*/
public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2;
/**
* Window type: system window, such as low power alert. These windows
* are always on top of application windows.
* In multiuser systems shows only on the owning user's window.
*/
public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3;
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT优先级比较高,把后一个view改为WindowManager.LayoutParams.TYPE_SYSTEM_ALERT就能获得焦点了.