27

I what my actionbar to have a title and homeAsUp but not the logo or icon.

like this:

enter image description here

I tried this:

actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("My Profile");
actionBar.setDisplayUseLogoEnabled(false);

But it gives the application icon between the title and back arrow

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • 1
    Why do you not want the icon to be present? Would it notbe easier for your users to see which app they are using after they receive a call etc? – Graham Smith Dec 04 '12 at 14:39
  • 1
    **I don't believe that inter-platform consistency between an app's different versions is as important than consistency between apps on a single platform** by Juhani – LOG_TAG Mar 11 '14 at 09:43
  • 1
    Some time we need this feature when your non geeky boss ask you to do the iOS UI pattern in Android! it's definitely one of the bad practices in Android! but we have to do it! if we comment on that then we are noted! :) – LOG_TAG Mar 11 '14 at 09:50

8 Answers8

45
actionBar = getSupportActionBar();    
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("My Profile");
actionBar.setDisplayUseLogoEnabled(false);
Aleksey Shulga
  • 626
  • 5
  • 4
  • From documentation: **Home is presented as either an activity icon or logo** The method: `setDisplayShowHomeEnabled (boolean showHome)` http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowHomeEnabled(boolean) – sromku Dec 04 '12 at 14:48
  • 1
    i find with ASB, if you setDisplayHomeAsUpEnabled(false); setHomeButtonEnabled(true); will do the same: title with up indicator, and without icon. – oscarthecat Oct 30 '13 at 08:39
10

Open your styles.xml file and add below codes in your Actionbar style

<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">@android:color/transparent</item> <--this do the magic!

p/s: I'm using Actionbar Sherlock and this works just fine

Qiqi Abaziz
  • 3,363
  • 3
  • 16
  • 12
5

If you do not want the icon in particular activity.

getActionBar().setIcon(
   new ColorDrawable(getResources().getColor(android.R.color.transparent)));
Laksh
  • 6,717
  • 6
  • 33
  • 34
4

To hide action bar icon following methods works for me

method-1:getActionBar().setIcon(android.R.color.transparent);
method-2:getActionBar().setIcon(null);
diordna
  • 550
  • 5
  • 14
2

Try to set this thing

actionBar.setLogo(null);
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
2
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));

it works for me.

Nazik
  • 8,696
  • 27
  • 77
  • 123
0

To hide the icon as well try using setIcon(null)

actionBar = getSupportActionBar();
actionBar.setTitle("My Profile");
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setIcon(null);
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
Joseph Earl
  • 23,351
  • 11
  • 76
  • 89
0
getActionBar().setHomeButtonEnabled(true);//used to navigate to home
 getActionBar().setDisplayHomeAsUpEnabled(false);//used to hide the left caret symbol
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52