gpt4 book ai didi

java - 使用WindowManager添加 View 时如何处理所有按键事件?

转载 作者:行者123 更新时间:2023-12-02 01:51:12 25 4
gpt4 key购买 nike

问题出在服务 View 后退按钮给了我响应,但主页和最近的应用程序按钮没有触发

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_HOME: //Not getting
minimizeApp();
return true;

case KeyEvent.KEYCODE_BACK: //getting
finish(false);
return true;

case KeyEvent.KEYCODE_APP_SWITCH: //Not getting
//minimizeApp();
return true;
}
return true;
}

在同一服务中,我尝试添加和删除不同的标志,但无法得到我想要的。

mLayoutParams =new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
,
PixelFormat.TRANSLUCENT);

我按下“后退”键,但我想捕获按下主页和最近应用程序的事件。

最佳答案

已更新我得到了解决方案

  li = LayoutInflater.from(this);
LinearLayout lia= new LinearLayout(this) {

//home or recent button
public void onCloseSystemDialogs(String reason) {

if (reason.equals("homekey")){
finisha(false);
}
if (reason.equals("recentapps")){
finisha(false);

}

}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
|| event.getKeyCode() == KeyEvent.KEYCODE_APP_SWITCH
|| event.getKeyCode() == KeyEvent.KEYCODE_HOME
) {

//The Code Want to Perform.
// return true;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_HOME){

}

if (event.getKeyCode() == KeyEvent.KEYCODE_APP_SWITCH){

}
return super.dispatchKeyEvent(event);
}
};

lia.setFocusable(true);

final View root = (View) li.inflate(R.layout.layout_alias_locker, lia);

关于java - 使用WindowManager添加 View 时如何处理所有按键事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57425392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com