Tabs without icon

前端 未结 5 637
悲&欢浪女
悲&欢浪女 2020-12-18 22:39

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条回答
  • 2020-12-18 22:56

    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.

    0 讨论(0)
  • 2020-12-18 23:03

    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)

    0 讨论(0)
  • 2020-12-18 23:05

    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);
    
    0 讨论(0)
  • 2020-12-18 23:05

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

    0 讨论(0)
  • 2020-12-18 23:16
     TabSpec laboratorySpec = tabHost.newTabSpec("Laboratory");
     laboratorySpec.setIndicator("Laboratory");
     Intent laboratoryIntent = new Intent(this, LaboratoryActivity.class);
     laboratorySpec.setContent(laboratoryIntent);
    

    worked for me

    0 讨论(0)
提交回复
热议问题