好吧,通过将此代码添加到详细信息片段中,我能够得到我想要的结果。可能不理想,但它有效:
@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);