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?

Community
  • 1
  • 1
prashant
  • 3,570
  • 7
  • 40
  • 50

8 Answers8

129

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

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 10
    Any way to remove the icon through XML? – James Oct 28 '11 at 06: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 `showTitle` – James Oct 28 '11 at 06: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. `useLogo|showHome|showTitle` – Cel Mar 18 '12 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 Mar 24 '12 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); – Krishna Shrestha Sep 08 '13 at 05: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

Bert Regelink
  • 2,696
  • 23
  • 17
  • does this work with Action Bar sherlock? I am trying it but I cant get it to work. – Joel Dean Aug 04 '13 at 17:27
  • this isnt working with me, it needs API 11 and I want to support earlier versions – Kaloyan Roussev Oct 12 '13 at 09: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. – Abid H. Mujtaba Nov 27 '13 at 05: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 Oct 17 '14 at 01:36
15

Try

getActionBar.setIcon(R.color.transparent);
Adí
  • 854
  • 12
  • 27
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...
}
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
1
actionBar.setIcon(R.color.transparent);

actionBar.setTitle("");
Hossein Amini
  • 716
  • 9
  • 21
1

Try this in onCreate()

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

user android.R.color.transparent

Vrajesh
  • 1,312
  • 19
  • 25
0

Try this combination

    getSupportActionBar().setHomeButtonEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setIcon(R.color.transparent);
    getSupportActionBar().setDisplayShowTitleEnabled(true)
Satheesh
  • 723
  • 7
  • 18
-2

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

getActionbar().hide();
smac89
  • 39,374
  • 15
  • 132
  • 179