Remove icon/logo from action bar on android

148,982

Solution 1

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).

Solution 2

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.

Solution 3

If you do not want the icon in particular activity.

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

Solution 4

This worked for me

getActionBar().setDisplayShowHomeEnabled(false);

Solution 5

Calling

mActionBar.setDisplayHomeAsUpEnabled(true);

in addition to,

mActionBar.setDisplayShowHomeEnabled(false);

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

Share:
148,982

Related videos on Youtube

Hrafn
Author by

Hrafn

Coffee &amp; code. Mostly coffee.

Updated on July 08, 2022

Comments

  • Hrafn
    Hrafn almost 2 years

    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.

    • Mgamerz
      Mgamerz over 11 years
      You could have just read the API guide on the actionbar. It says it right in the guide.
    • Hrafn
      Hrafn over 11 years
      Every piece of information is somewhere to be found.
    • DForck42
      DForck42 over 7 years
      can you show us what you've tried? what you've found previously that doesn't work?
    • Hrafn
      Hrafn over 7 years
      @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.
  • Igor Čordaš
    Igor Čordaš almost 11 years
    Quite a nice trick, thanks! It even stops taking up space in action bar!
  • Boy
    Boy over 10 years
    getActionBar().setIcon(android.R.color.transparent); seems to be sufficient
  • Jagdeep Singh
    Jagdeep Singh over 10 years
    Thanks ..it worked in code also... actionBar.setIcon(android.R.color.transparent);
  • Bytecode
    Bytecode over 10 years
    Excellent answer ...:)
  • Ron
    Ron over 10 years
    LOL'd at the comment! Great and simple answer.
  • horkavlna
    horkavlna about 10 years
    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.
  • Roger Keays
    Roger Keays almost 10 years
    This puts the action bar under the tabs / navigation bar. Apparently this behaviour is "by design" ... code.google.com/p/android/issues/detail?id=36191
  • Matt W
    Matt W almost 10 years
    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: <color name="transparent">#00000000</color> and reference that instead of getting the value from Android.
  • Hristo Valkanov
    Hristo Valkanov almost 10 years
    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 :)
  • Jose_GD
    Jose_GD almost 10 years
    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
  • Nilzor
    Nilzor almost 10 years
    @jose_GD: android:displayOptions is v11 and up only, so you need both to be backwards compatible.
  • lytridic
    lytridic almost 10 years
    getSupportActionBar().setIcon(android.R.color.transparent)
  • Aedis
    Aedis over 9 years
    I would change this to: ColorDrawable cd = new ColorDrawable(getResources().getColor(android.R.color.transp‌​arent)); cd.setBounds(0,0,0,0); getActionBar().setIcon(cd); Without setting the bounds, the transparent icon still uses up space
  • jesses.co.tt
    jesses.co.tt over 9 years
    this works to set hide the icon/title... but it still draws the background (which can be hidden with <item name="android:background">@android:color/transparent</item> ) ... however, the whitespace/padding is still present and my action items are not left justified... thoughts on how to fix that ?
  • JohnyTex
    JohnyTex over 9 years
    1x1 size transparent .png drawable?
  • Rowan
    Rowan about 9 years
    @Aedis : still shows empty space at left of the actionbar. any suggestions?
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • Hrafn
    Hrafn about 9 years
    Not in anyway does this answer the question. I knew about this feature, but I was asking for XML!
  • acrespo
    acrespo almost 9 years
    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
    acrespo almost 9 years
    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?
  • Charles Madere
    Charles Madere almost 9 years
    @acrespo hmm I know what you're talking about but I haven't investigated a solution for that one, sorry.
  • acrespo
    acrespo almost 9 years
    What I ended up doing is setting <application (...) android:logo="@android:color/transparent"> (...) in my AndroidManifest.xml and forcing useLogo for displayOptions in my style like this <item name="android:displayOptions">showHome|useLogo|homeAsUp|show‌​Title</item> <item name="displayOptions">showHome|useLogo|homeAsUp|showTitle</i‌​tem>. 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
  • DiscDev
    DiscDev almost 9 years
    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.
  • Baron
    Baron over 8 years
    This is a better solution: <item name="android:icon">@null</item>
  • luiscosta
    luiscosta over 8 years
    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!!
  • hellaandrew
    hellaandrew over 8 years
    Is there a good reason why I can't use getActionBar().setIcon(null); ? It seems to be working out for me as well.
  • Atul O Holic
    Atul O Holic almost 8 years
    @Hrafn - I thought XML was the preferred answer not the ONLY answer. :( I guess its still helping people. :)