13

I'm having a look at the "Tab Layout" tutorial which is perfectly clear and my question is very simple : is it possible to create tabs with no icon, just a single title?

Cristian
  • 198,401
  • 62
  • 356
  • 264
thomaus
  • 6,170
  • 8
  • 45
  • 63

5 Answers5

13

is it possible to create tabs with no icon, just a single title?

Yes. If you are doing something like:

spec = tabHost.newTabSpec("tab_name").setIndicator("Some tab",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);

Change it to:

spec = tabHost.newTabSpec("tab_name").setIndicator("Some tab").setContent(intent);
Cristian
  • 198,401
  • 62
  • 356
  • 264
3

I guess you are reading Tab layout tutorial There you can see that they use following function to set title and icon:

setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums))

Same function has another version, which does not take drawable as parameter

.setIndicator("Albums")

So, this second version of the function creates tab without icon. Simple answer - yes, you can create tabs with title only.

dstefanox
  • 2,222
  • 3
  • 19
  • 21
2

You can set a fixed height of the tabwidged.

In the Code:

tabHost.getTabWidget().getChildAt(0).getLayoutParams().height=n;

Or in the XML: ..

android:layout_height="n"

.. (with android:gravity you can affect where ur tabwidget gets cut)

urarne
  • 41
  • 2
1

You can use TabSpec.setIndicator(View view) method to customize your indicator, this method was introduced since API level 4.

Reno
  • 33,594
  • 11
  • 89
  • 102
Adrop
  • 11
  • 1
0
 TabSpec laboratorySpec = tabHost.newTabSpec("Laboratory");
 laboratorySpec.setIndicator("Laboratory");
 Intent laboratoryIntent = new Intent(this, LaboratoryActivity.class);
 laboratorySpec.setContent(laboratoryIntent);

worked for me

Mr_Hmp
  • 2,474
  • 2
  • 35
  • 53