那么,我能够通过将此代码添加到细节碎片中来获得我想要的结果。也许并不理想,但它的工作原理:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
this.getSherlockActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setRetainInstance(true);
}
更新:
发现这可能是一个更好的解决方案。它检测“细节”片段是否可见:
final DetailsFragment fragment = (DetailsFragment)getFragmentManager().findFragmentById(R.id.fragmentDetails);
if (fragment == null || fragment.isInLayout() == false)
this.getSherlockActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);