2014-02-28 73 views
1

我已經實現了右側菜單(帶有三個點)和左側的導航抽屜。Android - 如何隱藏操作欄上的應用程序圖標

我的應用程序圖標,我用:

getActionBar().setIcon(R.color.Transparent); 

但它發生在應用程序啓動時,它顯示的圖標,然後它去透明,我想簡單地初始化我的應用程序沒有圖標。

我也想知道如何將文本與我的應用/活動名稱居中。

app bar

+0

你應該閱讀這篇文章:http://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous由Cyril Mottier。它解釋了自定義樣式,特別是ActionBar,可以更高效地啓動您的應用程序。 – Fllo

回答

2

我會建議你使用樣式爲你的動作條。

在values文件夾下的styles.xml文件中,您可以對其進行編輯,使AppTheme爲您的操作欄使用特定的樣式。在這種特定的風格中,你可以聲明你的圖標屬性。這讓我們從動態欄知道你有一個特定的圖標,並顯示它開始消除暫停。

styles.xml

<resources> 

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="actionBarStyle">@style/MyActionBarStyle</item> 
</style> 


<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="icon">@android:color/transparent</item> 
</style> 
</resources> 

正如你可以在風格「AppTheme」我看到添加:

<item name="actionBarStyle">@style/MyActionBarStyle</item> 

這說明,我想我的應用程序考慮到了自定義樣式動作條被稱爲「MyActionBarStyle」

您還可以看到我,我宣佈風格:

<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="icon">@android:color/transparent</item> 
</style> 

在此聲明中,我可以將圖標設置爲drawable或color(正如我們在此實例中所做的那樣)。希望這可以幫助。

此外,此示例假定您正在使用支持庫。如果不是,那麼只要確保用'Holo'替換'AppCompat',用'android:icon'替換'icon',用'android:actionBarStyle'替換'actionBarStyle'。我瞭解到,難道:)

+0

它通過替換您告訴我替換的內容,並替換「android:」替換了「@ style /」,並通過「@ style/MyActionBarStyle」更改了應用程序主題的清單。謝謝 – Bugdr0id

1

如下您可以通過編程做到這一點:

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 

希望它能幫助!

商祺!

+0

此解決方案與我的類似,不起作用。它具有相同的效果:當應用程序啓動時顯示圖標,然後變爲透明。 – Bugdr0id

1

試試這個,動作條的支持,

setDisplayShowHomeEnabled(false); 
+0

工程就像一個魅力,謝謝! –

0

試試這個,

actionBar.setDisplayUseLogoEnabled(false); 
相關問題