Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Tabs without icons

Tags:

android

tabs

size

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?

like image 374
GideonKain Avatar asked Sep 09 '11 06:09

GideonKain


3 Answers

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

like image 118
Aurelian Cotuna Avatar answered Nov 14 '22 23:11

Aurelian Cotuna


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" />
like image 26
Nathan B Avatar answered Nov 15 '22 01:11

Nathan B


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);
like image 32
Mohit Kanada Avatar answered Nov 15 '22 00:11

Mohit Kanada