59

How can I remove the application icon & title which comes by default in an action bar?

There is a similar question here: Can i hide the App Icon from the Action Bar in Honeycomb?, but it doesn't talk about how to do it?

8 Answers 8

129

Call setDisplayShowHomeEnabled() and setDisplayShowTitleEnabled() on ActionBar, which you get via a call to getActionBar().

5
  • 10
    Any way to remove the icon through XML?
    – James
    Commented Oct 28, 2011 at 6:15
  • 8
    Just figured it out... you use abDisplayOptions and set your desired combination of useLogo, showHome, homeAsUp, showTitle, and showCustom. I wanted just the title with no icon, so I did <item name="abDisplayOptions">showTitle</item>
    – James
    Commented Oct 28, 2011 at 6:20
  • 7
    @James tried your xml letter for letter and that did not work (obviously), so to save others finding the correct thing it's e.g. <item name="android:displayOptions">useLogo|showHome|showTitle</item>
    – Cel
    Commented Mar 18, 2012 at 17:27
  • 1
    @Cel I'm pretty sure it's because I used Action Bar Sherlock and you did not. That's why the names are different, but otherwise the code is basically the same. I should've used the standard action bar to cover the more general case. Sorry!
    – James
    Commented Mar 24, 2012 at 16:50
  • 2
    yes it works perfectly but it also removes homeUpIndicatior from actionbar so if need HomeUpIcon and no need of logo icon then you can just set getActionBar.setIcon(R.color.transparent); Commented Sep 8, 2013 at 5:45
79

If you want to do it the XML way, then define a style (XML file) in the /res/values-v11/ folder with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="android:style/Theme.Holo">
        <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    </style>

    <style name="MyActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:displayOptions"></item>
    </style>
</resources>

In your AndroidManifest.xml set the theme defined above for your activity:

<activity
    ...
    android:theme="@style/MyTheme">
    ...
</activity>

This will remove the icon and the title and only display the action items. If you just want the title to be displayed, the use:

<item name="android:displayOptions">showTitle</item>

Or just the application logo:

<item name="android:displayOptions">showHome</item>

Or both (default)

<item name="android:displayOptions">showHome|showTitle</item>

Other options are available too, like: showCustom, useLogo, homeAsUp

4
  • does this work with Action Bar sherlock? I am trying it but I cant get it to work.
    – Joel Dean
    Commented Aug 4, 2013 at 17:27
  • this isnt working with me, it needs API 11 and I want to support earlier versions Commented Oct 12, 2013 at 9:21
  • 1
    To get it to work for API < 11 (AppCompat) simply repeat the repeat the item entries in the style blocks without "android:" in the name. This accesses the AppCompat attributes which need to be overridden for the new styles to work. Commented Nov 27, 2013 at 5:38
  • if you are displaying a logo instead of an icon (in the action bar), you want to use showHome|useLogo, if you only use "useLogo", it is not going to work. This is just an apart :)
    – yat0
    Commented Oct 17, 2014 at 1:36
15

Try

getActionBar.setIcon(R.color.transparent);
8
  • Wouldn't that just hide (not remove) it?
    – Leigh
    Commented Jul 30, 2013 at 20:57
  • Yes, that will hide it.
    – Adí
    Commented Jul 31, 2013 at 17:20
  • But is that the same as "removing it"? Typically, non-visible elements still take up space. But removed elements do not. So does the above actually achieve the same effect as the accepted answer.
    – Leigh
    Commented Jul 31, 2013 at 17:35
  • Kind of. It does not take up any space.
    – Adí
    Commented Jul 31, 2013 at 19:29
  • UPDATE: You can also add a transparent PNG in the dimensions of the ActionBarSherlock Icons, that would make sure you have enough space to tap on the default Back button on top left.
    – Adí
    Commented Sep 12, 2013 at 13:03
2

This will help you:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);

        //the rest of your code...
}
1
actionBar.setIcon(R.color.transparent);

actionBar.setTitle("");
1

Try this in onCreate()

ActionBar actionbar=getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(false);
actionbar.setIcon(android.R.color.transparent);

user android.R.color.transparent

0

Try this combination

    getSupportActionBar().setHomeButtonEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setIcon(R.color.transparent);
    getSupportActionBar().setDisplayShowTitleEnabled(true)
-2

If you are looking to simply remove the entire actiobar, you can try the hide method for actionBars:

getActionbar().hide();

Not the answer you're looking for? Browse other questions tagged or ask your own question.