Tabs without icon

2019-01-26 05: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?

5条回答
可以哭但决不认输i
2楼-- · 2019-01-26 05:52
 TabSpec laboratorySpec = tabHost.newTabSpec("Laboratory");
 laboratorySpec.setIndicator("Laboratory");
 Intent laboratoryIntent = new Intent(this, LaboratoryActivity.class);
 laboratorySpec.setContent(laboratoryIntent);

worked for me

查看更多
男人必须洒脱
3楼-- · 2019-01-26 05:56

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);
查看更多
\"骚年 ilove
4楼-- · 2019-01-26 06:02

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.

查看更多
地球回转人心会变
5楼-- · 2019-01-26 06:07

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

查看更多
祖国的老花朵
6楼-- · 2019-01-26 06:15

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)

查看更多
登录 后发表回答