gpt4 book ai didi

java - 无法关闭 popUpWindow

转载 作者:行者123 更新时间:2023-12-02 08:17:59 26 4
gpt4 key购买 nike

我创建了弹出窗口

 public void myPopUp()
{

LinearLayout myView = new LinearLayout(getApplicationContext());
pw = new PopupWindow(getApplicationContext());
pw.setContentView(myView);
myView.setBackgroundColor(Color.WHITE);
pw.setWidth(curWidth-100);
pw.setHeight(curHeight-100);
pw.showAtLocation(background, Gravity.CENTER, 0, 0);
}

并覆盖后退按钮按下以解除

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
getNewWH();
middle.removeView(bb);
if(statusBG==2)
{
log("statusBG = "+statusBG);
showFeed();
statusBG=1;
}
else
if(statusBG==1)
{
finish();
}
else
if (pw.isShowing()) {
log("here again");
pw.dismiss();
log("here");

}
return true;
}
return super.onKeyDown(keyCode, event);
}

正如你所理解的那样 - 当我按下后退按钮时我想关闭/隐藏弹出窗口,但现在我收到以下错误:(

05-12 12:27:15.373: ERROR/WindowManager(1259): Activity myClass.com.myClass has leaked window android.widget.PopupWindow$PopupViewContainer@44ec28a8 that was originally added here
05-12 12:27:15.373: ERROR/WindowManager(1259): android.view.WindowLeaked: Activity myClass.com.myClass has leaked window android.widget.PopupWindow$PopupViewContainer@44ec28a8 that was originally added here
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.view.ViewRoot.<init>(ViewRoot.java:247)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
05-12 12:27:15.373: ERROR/WindowManager(1259): at myClass.com.myClass.myPopUp(myClass.java:743)
05-12 12:27:15.373: ERROR/WindowManager(1259): at myClass.com.myClass$15.onClick(myClass.java:724)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.view.View.performClick(View.java:2408)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.view.View$PerformClick.run(View.java:8816)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.os.Handler.handleCallback(Handler.java:587)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.os.Handler.dispatchMessage(Handler.java:92)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.os.Looper.loop(Looper.java:123)
05-12 12:27:15.373: ERROR/WindowManager(1259): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 12:27:15.373: ERROR/WindowManager(1259): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 12:27:15.373: ERROR/WindowManager(1259): at java.lang.reflect.Method.invoke(Method.java:521)
05-12 12:27:15.373: ERROR/WindowManager(1259): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 12:27:15.373: ERROR/WindowManager(1259): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 12:27:15.373: ERROR/WindowManager(1259): at dalvik.system.NativeStart.main(Native Method)

任何人都可以帮助我并告诉我如何在我按下后退按钮时纠正弹出窗口吗?

附:抱歉我的英语不好,希望你理解我。问候,彼得。

最佳答案

通过后按关闭 PopupWIndow 但不关闭根 Activity 或 View 是为了设置焦点。popupWindow.setFocusable(true);

弹出窗口没有焦点,因此当按后退时,它会关闭主 Activity ,因为焦点位于主 Activity 上。

关于java - 无法关闭 popUpWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5978069/

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