gpt4 book ai didi

Android TabHost - 返回按钮

转载 作者:太空狗 更新时间:2023-10-29 15:36:39 24 4
gpt4 key购买 nike

我有一个使用 TabHost 的 Android 应用程序,根据所选选项卡调用其他应用程序的 Activity 简称为 Main.java。我试图覆盖 Main.java 类中的后退按钮事件,但它似乎没有看到它。我正在尝试显示一个对话框窗口并向用户确认他们要注销,如果他们单击“确定”,则完全关闭应用程序(不仅仅是发送到后台),如果他们单击“取消”,显然让它保持打开状态。关于为什么这似乎不起作用的任何建议?

@Override
public void onBackPressed()
{
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setMessage("Test dialog");
alert.show();
}

最佳答案

It turns out to be pretty easy. Add the following code to your child tab activity :

@Override
public void onBackPressed() {
this.getParent().onBackPressed();
}

Then in the TabActivity do the real logic:

 @Override
public void onBackPressed() {
// Called by children
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setMessage("Test dialog");
alert.show();
}

Otherwise, the children will intercept and consume the event without notifying the tab host.

关于Android TabHost - 返回按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16405564/

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