147

I've been trying to find some way of removing the icon/logo from the action bar but the only thing I've found after an hour of searching SO, Android's documentation and Google is how to remove the title bar in whole. That is not what I want. Only want to remove the icon/logo from the title bar.

Any one know how to accomplish this? Preferably I'd like to do this in XML.

Hrafn
  • 2,867
  • 3
  • 25
  • 44
  • 1
    You could have just read the API guide on the actionbar. It says it right in the guide. – Mgamerz Jan 30 '13 at 16:38
  • 6
    Every piece of information is somewhere to be found. – Hrafn Jan 31 '13 at 13:04
  • can you show us what you've tried? what you've found previously that doesn't work? – DForck42 Nov 09 '16 at 16:51
  • @DForck42 This question is really not relevant anymore (almost 4 years old). You can find plenty of ways of achieving this in the answers here below. – Hrafn Nov 10 '16 at 18:13

18 Answers18

228

Add the following code in your action bar styles:

<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">@android:color/transparent</item> <!-- This does the magic! -->

PS: I'm using Actionbar Sherlock and this works just fine.

Léo Lam
  • 3,870
  • 4
  • 34
  • 44
Qiqi Abaziz
  • 3,363
  • 3
  • 16
  • 12
  • 2
    Quite a nice trick, thanks! It even stops taking up space in action bar! – Igor Čordaš Jul 02 '13 at 09:32
  • 7
    Thanks ..it worked in code also... actionBar.setIcon(android.R.color.transparent); – Jagdeep Singh Nov 25 '13 at 10:05
  • 24
    Some Samsung devices display `@android:color/transparent` as BLACK. Seems crazy, but many device manufacturers override Android's default settings; including colors. Because of this, I would create a color in colors.xml like this: `#00000000` and reference that instead of getting the value from Android. – Matt W Jun 11 '14 at 01:55
  • Just wondering why both `android:displayOptions` and `displayOptions`? Furthermore, they're not related to the solution, what makes the "magic" is setting the icon color to transparent – Jose_GD Jun 27 '14 at 12:48
  • 1
    @jose_GD: android:displayOptions is v11 and up only, so you need both to be backwards compatible. – Nilzor Aug 01 '14 at 09:28
  • getSupportActionBar().setIcon(android.R.color.transparent) – lytridic Aug 02 '14 at 07:15
  • this works to set hide the icon/title... but it still draws the background (which can be hidden with @android:color/transparent ) ... however, the whitespace/padding is still present and my action items are not left justified... thoughts on how to fix that ? – jesses.co.tt Oct 09 '14 at 18:24
  • 1x1 size transparent .png drawable? – JohnyTex Oct 15 '14 at 10:23
  • This works, but in my case, when i have a search view and click it/expand it, the my app icon/logo reappears. Any ideas? – acrespo Jul 07 '15 at 14:44
  • This is a better solution: @null – Baron Oct 05 '15 at 20:32
115

If you do not want the icon in particular activity.

getActionBar().setIcon(
   new ColorDrawable(getResources().getColor(android.R.color.transparent)));    
Laksh
  • 6,717
  • 6
  • 33
  • 34
  • 45
    getActionBar().setIcon(android.R.color.transparent); seems to be sufficient – Boy Nov 10 '13 at 10:25
  • call method getActionBar().... is better solution this problem (remove icon from action bar) because if you use navigation bar and action bar , so your action bar will be above navigation bar. If you use setDisplayShowHomeEnabled(false) so navigation bar will be over action bar and you don't want this. – horkavlna Mar 30 '14 at 10:43
  • I would change this to: `ColorDrawable cd = new ColorDrawable(getResources().getColor(android.R.color.transparent)); cd.setBounds(0,0,0,0); getActionBar().setIcon(cd); ` Without setting the bounds, the transparent icon still uses up space – Aedis Aug 29 '14 at 22:37
  • 1
    @Aedis : still shows empty space at left of the actionbar. any suggestions? – Rowan Mar 30 '15 at 23:22
  • This works fine if you haven't set a logo. In my case I had to use `setLogo` instead of `setIcon` method. Still, great tip, got me on the right path!! – luiscosta Feb 05 '16 at 16:40
  • Is there a good reason why I can't use getActionBar().setIcon(null); ? It seems to be working out for me as well. – hellaandrew Feb 08 '16 at 08:43
58

If you've defined android:logo="..." in the <application> tag of your AndroidManifest.xml, then you need to use this stuff to hide the icon:

pre-v11 theme

<item name="logo">@android:color/transparent</item>

v11 and up theme

<item name="android:logo">@android:color/transparent</item>

The use of these two styles has properly hidden the action bar icon on a 2.3 and a 4.4 device for me (this app uses AppCompat).

Charles Madere
  • 6,642
  • 5
  • 35
  • 34
  • This works, but in my case, when i have a search view and click it/expand it, the my app icon/logo reappears. Any ideas? – acrespo Jul 07 '15 at 14:44
  • @acrespo hmm I know what you're talking about but I haven't investigated a solution for that one, sorry. – Charles Madere Jul 08 '15 at 19:56
  • 1
    What I ended up doing is setting ` (...)` in my `AndroidManifest.xml` and forcing `useLogo` for `displayOptions` in my style like this `showHome|useLogo|homeAsUp|showTitle showHome|useLogo|homeAsUp|showTitle`. This last part was important as in some devices (I think mostly post-lollipop) the damned searchview took the appIcon and put it in place of the logo, even if logo was set as transparent :s – acrespo Jul 08 '15 at 20:03
49

This worked for me

getActionBar().setDisplayShowHomeEnabled(false);
Brune
  • 1,060
  • 10
  • 20
  • 2
    This puts the action bar under the tabs / navigation bar. Apparently this behaviour is "by design" ... http://code.google.com/p/android/issues/detail?id=36191 – Roger Keays Jun 09 '14 at 17:31
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:02
  • This seems like it should be the answer - otherwise you're applying a global solution, which I doubt is what everyone wants. In my case, I want to show the logo on some pages, but other pages it doesn't make sense and clutters the action bar. – DiscDev Jul 21 '15 at 16:31
28

Calling

mActionBar.setDisplayHomeAsUpEnabled(true);

in addition to,

mActionBar.setDisplayShowHomeEnabled(false);

will hide the logo but display the Home As Up icon. :)

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:02
  • @Hrafn - I thought XML was the preferred answer not the ONLY answer. :( I guess its still helping people. :) – Atul O Holic May 31 '16 at 07:51
15

Be aware that:

<item name="android:icon">@android:color/transparent</item>

Will also make your options items transparent.

Tevlon
  • 151
  • 1
  • 3
13
    //disable application icon from ActionBar
    getActionBar().setDisplayShowHomeEnabled(false);

    //disable application name from ActionBar
    getActionBar().setDisplayShowTitleEnabled(false);
user61253764
  • 478
  • 5
  • 9
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:02
12
getActionBar().setIcon(android.R.color.transparent);

This worked for me.

dn_c
  • 614
  • 1
  • 9
  • 26
11

Remove or show the title using:

getActionBar().setDisplayShowTitleEnabled(true);

Remove or show the logo using:

getActionBar().setDisplayUseLogoEnabled(false);

Remove all:

getActionBar().setDisplayShowHomeEnabled(false);
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:03
9

you can also add below code in AndroidManifest.xml.

android:icon="@android:color/transparent"

It will work fine.

But I found that this gives a problem as the launcher icon also become transparent.

So I used:

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

and it worked fine.

But if you are having more than one activity and want to make the icon on an activity transparent then the previous approach will work.

Sam
  • 452
  • 5
  • 15
2
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
getActionBar().setDisplayHomeAsUpEnabled(true);
duggu
  • 37,851
  • 12
  • 116
  • 113
user3748515
  • 261
  • 2
  • 3
  • Welcome to Stack overflow! Usually answers similar to yours are considered rather low quality. For future reference you should consider adding some explanations about the code you provided and you should structure better the code (add 4 spaces to the beginning of each line, or select it all and click the {} symbol above the text box.) Also, you should pay more attention to the date of the question (over a year ago) and the fact that it's been already answered (the green check sign). Good luck on your programming :) – Hristo Valkanov Jun 17 '14 at 13:03
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:03
2

I used this and it worked for me.

        getActionBar().setIcon(
        new ColorDrawable(getResources().getColor(android.R.color.transparent)));
user2900761
  • 111
  • 1
  • 3
  • 15
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:03
1

I think the exact answer is: for api 11 or higher:

getActionBar().setDisplayShowHomeEnabled(false);

otherwise:

getSupportActionBar().setDisplayShowHomeEnabled(false);

(because it need a support library.)

David
  • 2,129
  • 25
  • 34
  • Not in anyway does this answer the question. I knew about this feature, but I was asking for XML! – Hrafn Mar 31 '15 at 11:04
1

go to your manifest an find the application tag

  android:icon="@android:color/transparent"// simply add this on place of your icon

..... ... ...

Avinash Ajay Pandey
  • 1,497
  • 12
  • 19
0

Qiqi Abaziz's answer is ok, but I still struggled for a long time getting it to work with the compatibility pack and to apply the style to the correct elements. Also, the transparency-hack is unneccessary. So here is a complete example working for v8 and up:

values\styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyActivityTheme" parent="@style/Theme.AppCompat">
        <item name="actionBarStyle">@style/NoLogoActionBar</item> <!-- pre-v11-compatibility -->
        <item name="android:actionBarStyle">@style/NoLogoActionBar</item>
    </style>
    <style name="NoLogoActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="displayOptions">showHome</item> <!-- pre-v11-compatibility -->
        <item name="android:displayOptions">showHome</item>
    </style>
</resources>

AndroidManifest.xml (shell)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">   
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
    <application android:theme="@android:style/Theme.Light.NoTitleBar">
        <activity android:theme="@style/PentActivityTheme"/>
    </application>
</manifest>
Nilzor
  • 18,082
  • 22
  • 100
  • 167
0

Go in your manifest and find the your activity then add this code:

android:theme="@android:style/Theme.NoTitleBar"

above line hide your Actionbar .

If you need to other feature you can see other options with (CLR + SPC).

A.A
  • 1,138
  • 1
  • 16
  • 29
0

The fastest way is to modify your Manifest.xml. If for example you want to remove the logo of activity "Activity", and leave the logo in other activities, you can do the following:

<activity
      android:name=".home.XActivity"
      android:logo="@android:color/transparent"
      android:configChanges="orientation|keyboardHidden" />
 <activity
      android:name=".home.HomeActivity"
      android:configChanges="orientation|keyboardHidden" />
0

None of the above worked.

But this did the trick:

override fun onCreate() {
    setContentView(R.layout.activity_main)

    setSupportActionBar(toolbar)
    toolbar.logo = null

(removed icon from toolbar)

Dan Alboteanu
  • 9,404
  • 1
  • 52
  • 40