Remove icon/logo from action bar on android
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. :)
Related videos on Youtube
Comments
-
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 over 11 yearsYou could have just read the API guide on the actionbar. It says it right in the guide.
-
Hrafn over 11 yearsEvery piece of information is somewhere to be found.
-
DForck42 over 7 yearscan you show us what you've tried? what you've found previously that doesn't work?
-
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š almost 11 yearsQuite a nice trick, thanks! It even stops taking up space in action bar!
-
Boy over 10 yearsgetActionBar().setIcon(android.R.color.transparent); seems to be sufficient
-
Jagdeep Singh over 10 yearsThanks ..it worked in code also... actionBar.setIcon(android.R.color.transparent);
-
Bytecode over 10 yearsExcellent answer ...:)
-
Ron over 10 yearsLOL'd at the comment! Great and simple answer.
-
horkavlna about 10 yearscall 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 almost 10 yearsThis 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 almost 10 yearsSome 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 almost 10 yearsWelcome 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 almost 10 yearsJust wondering why both
android:displayOptions
anddisplayOptions
? Furthermore, they're not related to the solution, what makes the "magic" is setting the icon color to transparent -
Nilzor almost 10 years@jose_GD: android:displayOptions is v11 and up only, so you need both to be backwards compatible.
-
lytridic almost 10 yearsgetSupportActionBar().setIcon(android.R.color.transparent)
-
Aedis over 9 yearsI 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 -
jesses.co.tt over 9 yearsthis 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 over 9 years1x1 size transparent .png drawable?
-
Rowan about 9 years@Aedis : still shows empty space at left of the actionbar. any suggestions?
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
Hrafn about 9 yearsNot in anyway does this answer the question. I knew about this feature, but I was asking for XML!
-
acrespo almost 9 yearsThis 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 almost 9 yearsThis 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 almost 9 years@acrespo hmm I know what you're talking about but I haven't investigated a solution for that one, sorry.
-
acrespo almost 9 yearsWhat I ended up doing is setting
<application (...) android:logo="@android:color/transparent"> (...)
in myAndroidManifest.xml
and forcinguseLogo
fordisplayOptions
in my style like this<item name="android:displayOptions">showHome|useLogo|homeAsUp|showTitle</item> <item name="displayOptions">showHome|useLogo|homeAsUp|showTitle</item>
. 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 almost 9 yearsThis 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 over 8 yearsThis is a better solution: <item name="android:icon">@null</item>
-
luiscosta over 8 yearsThis works fine if you haven't set a logo. In my case I had to use
setLogo
instead ofsetIcon
method. Still, great tip, got me on the right path!! -
hellaandrew over 8 yearsIs 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 almost 8 years@Hrafn - I thought XML was the preferred answer not the ONLY answer. :( I guess its still helping people. :)