17

I use action bar Sherlock but I need to remove title and icon from bar.

I used

getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);

It worked, icon and title disappeared but stil my items appeared in right. Is there a any way to completely remove title and icon instead of hide them. I found a similar question in stack-overflow but nobody answered it.

Edit

     Before my bar look like:   -- Icon Title MenuItem1 MenuItem2--
     After my bar look like:    --            MenuItem1 MenuItem2--
     I want my bar look like:   -- MenuItem1 MenuItem2
SavasCinar
  • 667
  • 3
  • 8
  • 25
  • 1
    You say "it worked", yet you are still not happy. Please consider using more words, or perhaps even pictures, to explain what your problem is. – CommonsWare May 02 '12 at 16:51
  • Can I ask a related question here? I also tried removing the icon and title by setting the displays to false. I inflate a custom view to replace the icon and title. It works, however, before the custom view inflates, I can see the icon and title in place. Any thoughts on that? – user1923613 Apr 24 '13 at 04:20
  • Thanks for the commands to hide the icon and the title! Very useful, even though you just stated it as question. – James Cameron May 26 '13 at 21:31

4 Answers4

10

Your "menu items" will never appear be aligned to the left. They will be aligned to the right. The left is for your title and icon (presently removed) and navigation (tabs, list, etc.). If you have enough action bar items, they will flow over to the left side, but they will always start from the right. This cannot be altered via the Android SDK.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
8

You can refer this code then you can get solution...just apply as per your requirment....

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

RelativeLayout relative = new RelativeLayout(getApplicationContext());

TextView tv1 = new TextView(this);
         tv1.setText("Test1");
         tv1.setTextColor(Color.GREEN);
         tv1.setPadding(3,13,3, 12);
         tv1.setId(1);
         tv1.setOnClickListener(this);

TextView tv2 = new TextView(this);
         tv2.setText("Test2");
         tv2.setTextColor(Color.GREEN);
         tv2.setPadding(3,13,3,12);
         tv2.setId(2);
         tv2.setOnClickListener(this);

TextView tv3 = new TextView(this);
         tv3.setText("Test3");
         tv3.setTextColor(Color.GREEN);
         tv3.setPadding(3,13,3, 12);
         tv3.setId(3);
         tv3.setOnClickListener(this);

TextView tv4 = new TextView(this);
         tv4.setText("Test3");
         tv4.setTextColor(Color.GREEN);
         tv4.setPadding(3,13,3, 12);
         tv4.setId(4);
         tv4.setOnClickListener(this);

LinearLayout ll = new LinearLayout(this);
             ll.addView(tv1);
             ll.addView(tv2);
             ll.addView(tv3);
             ll.addView(tv4);

relative.addView(ll);
actionBar.setCustomView(relative);
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
rajani
  • 81
  • 1
  • 1
2
getSupportActionBar().setIcon(android.R.color.transparent);
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
0

You can do this by using Contextual menu over Action Bar. Check the Sherlock ABS Demos, there is an Activity: ActionModes, it shows a very simple example which may be of use for you.

miroslavign
  • 2,033
  • 2
  • 24
  • 26