【问题标题】:What is the command to return to your main screen in an app?在应用程序中返回主屏幕的命令是什么?
【发布时间】:2010-11-16 05:21:01
【问题描述】:

当用户在不同的班级并点击手机上的返回/返回按钮时,我如何让应用返回到“主”屏幕?

现在,当他们访问不同的课程并点击返回按钮时,它会返回 Droid 的主屏幕,而不是应用程序的主屏幕 - 我如何让它返回主屏幕应用程序?

谢谢!

【问题讨论】:

    标签: android command homescreen


    【解决方案1】:

    使用 Activity 类的 OnBackPressed() 方法。 制定条件:

    public void onBackPressed(){    
    if(conditon)
      {
        detailInfoList.setVisibility(View.VISIBLE);//or anything that you want to show
      }
    }
    

    【讨论】:

      【解决方案2】:

      你不能,

      主页按钮是唯一无法阻止表单关闭应用的按钮。这样做是为了让您无法阻止应用程序中的用户(如病毒)。

      返回菜单和研究等其他键是可能的

      在你的活动中

      @Override
          public boolean onKeyDown(int keyCode, KeyEvent event) {
              if(event.getAction() == MotionEvent.ACTION_DOWN){
                  if(keyCode == 82){
                     Log.i("jason","released on menu");
                     //change view
                     //return so that the other behavior (leaving the activity) is not tirggered
                     return false;
              }   
              }
              Log.i("jason","actual key code "+keyCode);
              return super.onKeyDown(keyCode, event);
          }
      

      【讨论】:

      • 啊,如果我使用后退/返回按钮会怎样?例如,如果我向用户显示一个 result.xml 文件,并且如果他们按下返回/返回按钮,它会将他们带回到应用程序的主屏幕而不是机器人的主屏幕?
      • 我稍微改了一下代码,你想要的是抓住关键,改变视图,然后不调用超级以避免退出应用程序。我使用返回返回一个屏幕和菜单返回我的应用程序中的主菜单
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多