我在我的应用程序中使用操作栏片段。当屏幕旋转操作栏内容丢失时,请建议如何保留它们。这是我为此做的代码
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if(currentDisplayedCase != null) {
outState.putInt(DISPLAY_CASE_KEY, currentDisplayedCase.intValue());
}
outState.putString(ACTION_BAR_TEXT, textView1.getText().toString());
}
并在 onCreate 方法中
if(savedInstanceState!=null&&savedInstanceState.containsKey(ACTION_BAR_TEXT))
textView1.setText(savedInstanceState.getString(ACTION_BAR_TEXT, null));