115

My application's main icon consists of two parts in one image: a logo and a few letters below it. This works well for the launcher icon for the app, but when the icon appears on the left edge of the ActionBar, the letters get cut off and it doesn't look good.

I would like to provide the ActionBar with a separate version of the icon, with only the "logo" part and not the letters beneath it, but so far have been coming up empty. I honestly can't find any answer to this, and I can't even find the question itself anywhere.

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
Phil Ringsmuth
  • 2,037
  • 4
  • 20
  • 29

8 Answers8

219

The ActionBar will use the android:logo attribute of your manifest, if one is provided. That lets you use separate drawable resources for the icon (Launcher) and the logo (ActionBar, among other things).

Joe
  • 42,036
  • 13
  • 45
  • 61
49

In AndroidManifest.xml:

<application
    android:icon="@drawable/launcher"
    android:label="@string/app_name"
    android:name="com..."
    android:theme="@style/Theme">...</Application>

In styles.xml: (See android:icon)

<style name="Theme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:icon">@drawable/icon</item>
</style>
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • *android:logo* will work as well. I don't know the difference. – AlikElzin-kilaka Nov 28 '12 at 14:24
  • Sorry for tearing up healing wounds :-) But the difference is that the style change solution suggested here applies the custom icon only to the action bar, where as defining the `android:logo` in the manifest might affect other areas as well. – dbm Sep 12 '13 at 06:54
  • @dbm, can you please give an example of 'other areas'? – AlikElzin-kilaka Sep 12 '13 at 08:58
  • 2
    Yea, I got so curious I started googleing on it and this is what the Android developer site says: http://developer.android.com/guide/topics/manifest/application-element.html#logo. It's not clear to me how this is different from the `andorid:icon` attribute, though: http://developer.android.com/guide/topics/manifest/application-element.html#icon – dbm Sep 13 '13 at 10:21
  • 2
    [Action Bar doc](http://developer.android.com/guide/topics/ui/actionbar.html#Logo) also says you can add `android:icon` to the `` element, so you could easily change it for different activities. I tried that and it worked great. No need to mess with a custom theme or worry about affecting all the activities. – Jason Sep 20 '13 at 21:56
  • @kilaka I think the different is that `android:logo` doesn't work with support library (AppCompat). – fikr4n Nov 25 '13 at 03:29
  • i want to add an image to the extreme left of app logo on action bar, how can i do it ?? Is it possible – Sagar Devanga Nov 24 '14 at 10:58
20

Please try this line

getSupportActionBar().setHomeAsUpIndicator(R.drawable.back_arrow);
8

If you are using AppCompat, the only way to set the ActionBar icon on devices running Gingerbread (API 10) or below is by setting the android:icon attribute in every Activity in your manifest or setting the drawable programatically.

<manifest>
    <application>
        ...
        <activity android:name="com.your.ActivityName"
            ...
            android:icon="@drawable/ab_logo"/>
        ...
   </application>
</manifest>

Update: Be warned however that the application icon will be overridden if you set the android:icon attribute on the launch Activity. The only work around I know of is to have a splash or dummy Activity which then launches your main Activity.

TheIT
  • 11,919
  • 4
  • 64
  • 56
8

Inspired by TheIT, I just got this to work by manipulating the manifest file but in a slightly different fashion. Set the icon in the application setting so that the majority of the activities get the icon. On the activity where you want to show the logo, add the android:logo attribute to the activity declaration. In the following example, only LogoActivity should have the logo, while the others will default to icon.

<application
    android:name="com.your.app"
    android:icon="@drawable/your_icon"
    android:label="@string/app_name">

    <activity
        android:name="com.your.app.LogoActivity"
        android:logo="@drawable/your_logo"
        android:label="Logo Activity" >

    <activity
        android:name="com.your.app.IconActivity1"
        android:label="Icon Activity 1" >

    <activity
        android:name="com.your.app.IconActivity2"
        android:label="Icon Activity 2" >

</application>

Hope this helps someone else out!

proudgeekdad
  • 3,424
  • 6
  • 42
  • 40
6

Please Try, if use "extends AppCompatActivity" and present actionbar.

 ActionBar eksinbar=getSupportActionBar();
if (eksinbar != null) {
    eksinbar.setDisplayHomeAsUpEnabled(true);
    eksinbar.setHomeAsUpIndicator(R.mipmap.imagexxx);
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Mustafa
  • 69
  • 1
  • 4
4

creating logo

in folders "drawable-..." create in all of them logo.png . The location of the folders: [YOUR APP]\app\src\main\res

In AndroidManifest.xml add line: android:logo="@drawable/logo"

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:logo="@drawable/logo"
    ...

that's it.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
awariat
  • 331
  • 1
  • 5
  • 22
0

Might wanna check this, got everything you need for your app icons

http://developer.android.com/guide/practices/ui_guidelines/icon_design.html

update

I think by default it uses your launcher icon... Your best bet is to create a separate image... Designed for the action bar and using that. For that check: http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems

Stevanicus
  • 7,561
  • 9
  • 49
  • 70
  • Thank you for that link, and I may end up removing the letters from my icon and using the same "logo" icon throughout the app, but I may still need to use a smaller version of it, or a slightly different version of it on the ActionBar, and that's what I'm trying to find out. – Phil Ringsmuth Jun 14 '11 at 23:53