7

I've setup my tabs as follows:

 spec = tabHost.newTabSpec("tab1").setIndicator("Tab 1").setContent(intent);
    tabHost.addTab(spec);

And now I have a tab that has no icon, only a title, but it just leaves an icon-sized blank space with the Title at the bottom - I tried adjusting the layout_height in the xml, but then the text is gone because it is rendered below the cutoff point.

How can I change the size of a tab, and have the title displayed without an icon?

GideonKain
  • 744
  • 1
  • 12
  • 27

4 Answers4

11

The answer is simple: You can't. The default android tab will always leave some blank space for the image. But you can create your own tabs to compensate that "restriction" in the default tab. Here is a very good tutorial to create custom tabs.

http://joshclemm.com/blog/?p=136

Good luck, Arkde

Aurelian Cotuna
  • 3,076
  • 3
  • 29
  • 49
  • Ya! Worked great - had to change the tab orientation in the XML and reading comments figured out how to add an intent. Thanks Arkde! – GideonKain Sep 09 '11 at 07:29
2

Changing the TabWidget layout_height and gravity in xml worked for me. The text does not center in the tab but is aligned along the bottom just like before.

<TabWidget android:id="@android:id/tabs"
  android:layout_width="fill_parent" android:layout_height="40dp"
  android:gravity="bottom" />
Nathan B
  • 21
  • 5
1

Change your tabhost size from layout and for display only Tab Tile write code as per below code snippets

tabhost=getTabHost();


intent = new Intent(this,MainActivity.class);
spec1 = tabhost.newTabSpec("").setIndicator("main_tab");
spec1.setContent(intent);
tabhost.addTab(spec1);

intent = new Intent(this,xyz.class);
spec2 = tabhost.newTabSpec("").setIndicator("first_tab");
spec2.setContent(intent);
tabhost.addTab(spec2);
Mohit Kanada
  • 15,274
  • 8
  • 31
  • 41
  • I did this and thats why it appeared as a big gray box with no icon and title at bottom - Arkde's solution seems to be the proper workaround – GideonKain Sep 09 '11 at 09:29
0
// Center text displayed on a first tab
View view = _tabHost.getTabWidget().getChildAt(0);
if (view != null) {
    // Hide icon
    View tabImage = view.findViewById(android.R.id.icon);
    if (tabImage != null) {
        tabImage.setVisibility(View.GONE);
    }
    // Find text
    TextView tabTitle = (TextView) view.findViewById(android.R.id.title);
    if (tabTitle != null) {
        // Change text gravity
        tabTitle.setGravity(Gravity.CENTER);
        // Remove text view from it's parent and re-add back to reset layout parameters
        ViewGroup parent = (ViewGroup) tabTitle.getParent();
        parent.removeView(tabTitle);
        parent.addView(tabTitle);
        // New default layout parameters will have height set to WRAP_CONTENT, change it to MATCH_PARENT
        ViewGroup.LayoutParams params = tabTitle.getLayoutParams();
        params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    }
}
Eugene Mymrin
  • 5,736
  • 1
  • 14
  • 6