0

我已经处理了 android manifest 中的屏幕旋转配置更改,它适用于以对话框为主题的活动,但是对于这些菜单组,在选择菜单项(在 onOptionsItemSelected 中)后打开的菜单组在我旋转屏幕时仍然关闭。我可以在 onConfigurationChanged 中处理这些吗?或者,还有更好的方法?我附上了打开子菜单的代码。

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getGroupId() == R.id.submenu) {
      if (item.getItemId() == this.submenu) {
         return true;
      }
      this.value = item.getItemId();
      item.setChecked(true);
      //do something with value
      return true;
   }
   //...
   return super.onOptionsItemSelected(item);
}
4

2 回答 2

3

你需要覆盖

    @Override
 public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);
 }

但要做到这一点,您必须通过将标签添加到活动级别的清单文件中来指定您将自己处理的配置更改

     android:configChanges=["mcc", "mnc", "locale",
                             "touchscreen", "keyboard", "keyboardHidden",
                             "navigation", "orientation", "screenLayout",
                             "fontScale", "uiMode"]

on onConfigurationChanged 保存状态并在 onResume 上重新加载

于 2011-05-20T17:11:08.340 回答
0

这最终成为一个非常简单的修复。android:configChanges="orientation"我需要在 AndroidManifest中将这一行添加到我的活动中。

于 2011-06-14T03:30:42.597 回答