Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove title and icon completetly in Actionbar sherlock?

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
like image 370
SavasCinar Avatar asked May 02 '12 16:05

SavasCinar


People also ask

How do I remove text from action bar?

If we want to remove the ActionBar only from specific activities, we can create a child theme with the AppTheme as it's parent, set windowActionBar to false and windowNoTitle to true and then apply this theme on an activity level by using the android:theme attribute in the AndroidManifest. xml file.

How do I remove the action bar?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.

What is action bar icon?

The ActionBar, now known as the App Bar, is a consistent navigation element that is standard throughout modern Android applications. The ActionBar can consist of: An application icon. An "upward" navigation to logical parent. An application or activity-specific title.


3 Answers

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.

like image 66
CommonsWare Avatar answered Oct 16 '22 09:10

CommonsWare


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);
like image 20
rajani Avatar answered Oct 16 '22 10:10

rajani


getSupportActionBar().setIcon(android.R.color.transparent);
like image 38
Pratik Butani Avatar answered Oct 16 '22 09:10

Pratik Butani