2015-01-10 43 views
-1

我嘗試了很多方法,但無法在ActionBar中添加徽標。無法在ActionBar,Android API中添加徽標<11

我建立應用程序與minSdkVersion = 9targetSdkVersion = 21,我成功地改變了顏色動作條的,並將其與API < 11工作,但不能添加標誌呢!

我google了很多,也讀了很多回答stackoverflow但沒有任何工作。

我需要在這裏

enter image description here

我厭倦了manifest文件如添加標識標誌,

<application android:logo="@drawable/ic_launcher"> 

<activity android:logo="@drawable/ic_launcher"> 

,但它不工作!

我還創建res/values/themes.xml文件

<style name="CustomActionBarTheme" 
     parent="@style/Theme.AppCompat"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <item name="actionBarStyle">@style/MyActionBar</item> 
</style> 

<style name="MyActionBar" 
     parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 

    <item name="android:logo">@drawable/ic_launcher</item> 
    <item name="logo">@drawable/ic_launcher</item> //this is for support v7 
</style> 

回答

1

我明白了。 nadavfima在8-19-14之前回答了這個問題。如上所述:

getSupportActionBar().setDisplayShowHomeEnabled(true); 
getSupportActionBar().setIcon(R.drawable.ic_launcher); 

添加此代碼後,您將有一個操作欄圖標。請將此問題確認爲已回答