簡體   English   中英

未顯示操作欄的內容

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM