Customizing tabs on state in Android

后端 未结 2 815
遥遥无期
遥遥无期 2020-12-04 22:50

I know how to put the icon on each tab, that is no problem. I also ran across this : [Stack Overflow thread on pretty much same thing][1]

I followed one of the links

相关标签:
2条回答
  • 2020-12-04 23:04

    You could use a View as an indicator, this way you can customize it the way you wish.

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(View MyView).setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    

    The first tab will use a View as its indicator and the second a CharSequence. Have a look at the actual TabSpec class (http://developer.android.com/reference/android/widget/TabHost.TabSpec.html).

    0 讨论(0)
  • 2020-12-04 23:15

    The XML you've included here is a way of defining a drawable that lets you embed a case statement. It presents a different drawable depending on the state of the View it's being assigned to. As a drawable, you should save it as an xml file within the res/drawable folder of your project (for example tabselector.xml).

    To use it for the Tabhost, you need to construct the TabActivity as you normally would (as shown in this tutorial example).

    Then when you add each tab to the host, you specify the tabselector drawable as the indicator as shown for "TAB 1" below.

    Drawable mySelector = getResources().getDrawable(R.drawable.tabselector);
    
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1", mySelector).setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    

    Note: You cannot change the color of the tab backgrounds behind the icons at this point.

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