2013-10-22 51 views
0

不知道發生了什麼,我無法再在Android Studio中使用操作欄獲取應用程序。沒有視圖上的ActionBar

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    tools:ignore="MergeRootFrame"> 

    <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:text="hello"/> 
</LinearLayout> 

例如。它不會顯示操作欄。

+0

嘗試將'LinearLayout'替換爲'RelativeLayout',通常它可以工作。並調用'getActionBar()。show();'顯示操作欄。 –

回答

0

如果這是您的整個XML,那麼缺少節點theme。例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:theme="@style/Theme.AppCompat.Light" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    tools:ignore="MergeRootFrame"> 

    <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:text="hello"/> 
</LinearLayout> 

這是針對API Level 11或更高級別的解決方案。在這裏,您只需使用Holo主題之一來添加ActoinBar。
如果您使用API​​等級10或更低,請嘗試查看official Docs

+0

即使我在清單文件中使用應用主題? –

+0

它似乎還不想添加它。我仍然只是一個沒有操作欄的空白屏幕。 –

+0

'android:theme =「@ style/AppTheme」'in my manifest and '' 和 '<樣式名稱= 「動作條」 父= 「機器人:Theme.Holo.Light」> <項名稱= 「機器人:背景」> @顏色/ fb_dark_blue '在我的styles.xml中 什麼都沒有... –

0

我遇到了同樣的問題。 我認爲你應該讓你的活動在Android studio中擴展ActionBarActivity(不是Activity)。