2012-02-17 98 views
10

我正在使用eclipse,android 3.2。和運行android x86的虛擬機。 (v3.2)Android 3.2從操作欄刪除標題

我使用Holo主題,我想刪除操作欄標題和圖標。所以我做

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    ActionBar actionBar = getActionBar(); 
    actionBar.setDisplayShowTitleEnabled(false); 
    actionBar.setDisplayShowHomeEnabled(false); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.test); 
} 

它工作正常,但...

當應用程序開始時,我首先顯示標題和圖標,只有後,我看到他們消失。所以它不是很漂亮。

如果我使用調試,我可以看到只有當我離開onCreate setDisplayShowTitleEnabled生效。

那麼在活動顯示之前有沒有辦法隱藏標題和圖標?

謝謝。

回答

17

在您的清單

<activity android:name=".ActivityHere" 
    android:label=""> 
+10

警告:如果這是您的主要活動,您不想這樣做。它會從你的啓動器圖標中刪除標籤。在那種情況下,肯尼斯的答案應該可行。 – 2012-08-22 20:30:18

+0

是的,的確如此。我後來才發現。 – easycheese 2012-08-23 00:22:20

9

我通過在android清單中設置「NoActionBar」全息主題,然後在onCreate()中設置正常的全息主題來解決這個問題。

步驟1:在styles.xml中添加一個自定義主題資源。

<resources> 
    <style name="ActionBar.CustomTheme" parent="@android:style/Widget.Holo.ActionBar"/> 
    <style name="CustomTheme" parent="@android:style/Theme.Holo"> 
     <item name="android:actionBarStyle">@style/ActionBar.CustomTheme</item> 
    </style> 
</resources> 

第2步:在我的Android清單文件,我設置了主題爲應用程序和「NoActionBar」全息的啓動活動主題。

<application 
    android:theme="@style/CustomTheme 
    ... 

<activity 
    android:name="MainActivity" 
    android:theme="@android:style/Theme.Holo.NoActionBar"> 
    ... 

步驟3:在啓動活動的onCreate()...

@Override 
public void onCreate()(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setTheme(R.style.CustomTheme); // Set the custom theme which has the action bar. 
    ActionBar actionBar = getActionBar(); 
    ... 
+0

完美! Lag的不見了 – gpasci 2013-03-02 18:07:40

+0

沒有工作(Galaxy Tab 3) – 2014-05-27 16:12:03