[英]Contents of action bar not shown
我在應用中使用動作欄片段。當屏幕旋轉丟失的動作欄內容時,請提出如何保留它們的建議。 這是我為此做的代碼
@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));
您需要在清單文件android:configChanges =“ orientation”中的活動聲明中添加以下內容,即
<activity android:name=".myActivity" android:configChanges="orientation" android:label="@string/txt_app_name" android:theme="@style/myTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
這意味着您將要處理活動中的方向變化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.