Hrafn
Hrafn

Reputation: 2946

Remove icon/logo from action bar on android

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.

Upvotes: 147

Views: 150558

Answers (18)

Dan Alboteanu
Dan Alboteanu

Reputation: 10252

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)

Upvotes: 0

Jordi Alonso
Jordi Alonso

Reputation: 1

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" />

Upvotes: 0

Avinash Ajay Pandey
Avinash Ajay Pandey

Reputation: 1517

go to your manifest an find the application tag

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

..... ... ...

Upvotes: 1

dn_c
dn_c

Reputation: 614

getActionBar().setIcon(android.R.color.transparent);

This worked for me.

Upvotes: 12

Sam
Sam

Reputation: 452

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.

Upvotes: 9

Tiago Gouv&#234;a
Tiago Gouv&#234;a

Reputation: 16800

Remove or show the title using:

getActionBar().setDisplayShowTitleEnabled(true);

Remove or show the logo using:

getActionBar().setDisplayUseLogoEnabled(false);

Remove all:

getActionBar().setDisplayShowHomeEnabled(false);

Upvotes: 11

David
David

Reputation: 2179

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

getActionBar().setDisplayShowHomeEnabled(false);

otherwise:

getSupportActionBar().setDisplayShowHomeEnabled(false);

(because it need a support library.)

Upvotes: 1

A.A
A.A

Reputation: 1148

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

Upvotes: 0

Nilzor
Nilzor

Reputation: 18603

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>

Upvotes: 0

user61253764
user61253764

Reputation: 506

    //disable application icon from ActionBar
    getActionBar().setDisplayShowHomeEnabled(false);

    //disable application name from ActionBar
    getActionBar().setDisplayShowTitleEnabled(false);

Upvotes: 13

user3748515
user3748515

Reputation: 261

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

Upvotes: 2

user2900761
user2900761

Reputation: 121

I used this and it worked for me.

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

Upvotes: 2

Qiqi Abaziz
Qiqi Abaziz

Reputation: 3353

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.

Upvotes: 228

Charles Madere
Charles Madere

Reputation: 6832

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

Upvotes: 58

Atul O Holic
Atul O Holic

Reputation: 6792

Calling

mActionBar.setDisplayHomeAsUpEnabled(true);

in addition to,

mActionBar.setDisplayShowHomeEnabled(false);

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

Upvotes: 28

Tevlon
Tevlon

Reputation: 151

Be aware that:

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

Will also make your options items transparent.

Upvotes: 15

Brune
Brune

Reputation: 1060

This worked for me

getActionBar().setDisplayShowHomeEnabled(false);

Upvotes: 49

Laksh
Laksh

Reputation: 6727

If you do not want the icon in particular activity.

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

Upvotes: 115

Related Questions