I have 2 questions regarding tabHost: I created a tabHost with 2 tabs and for the tab names I use setIndicator (TextView) (I work with api level 4) my background header is white. I use the header selector to choose between diff images for the header.
I want the title text to be in bold only when selected / pressed. I was not able to do this using the selector that I have. can i do this at all? the idea is that in cases I use drawable a, I want the text to be bold. other cases are not in bold. same question regarding textColor.
it looks like an error - when the tab opens first, the text on the selected tab (the one I used in tabHost.setCurrentTab (tabId)) does not appear at all. after the first press / focus / focus, any other item looks good. any idea why and how to solve it?
early
on tabActivity -
TextView title1 = new TextView(MainActivity.getInstnace(), null, android.graphics.Typeface.NORMAL); TextView title2 = new TextView(MainActivity.getInstnace(), null, android.graphics.Typeface.NORMAL); title1.setText("teb11 title"); title1.setBackgroundResource(R.drawable.tabtitle); title1.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab1), null, null, null); title2.setText("tab22 title"); title2.setBackgroundResource(R.drawable.tabtitle); title2.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2), null, null, null); TabSpec tab1 = mTabHost.newTabSpec("tab1").setIndicator(title1).setContent(R.id.list1); TabSpec tab2 = mTabHost.newTabSpec("tab2").setIndicator(title2).setContent(R.id.list2); mTabHost.addTab(tab1); mTabHost.addTab(tab2); mTabHost.setCurrentTab(0);
tab1.xml selector
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/iconselect"/> <item android:state_pressed="true" android:drawable="@drawable/iconselect"/> <item android:drawable="@drawable/icon"/> </selector>
selector for tabTitle
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/tabselected"/> <item android:state_selected="true" android:drawable="@drawable/tab" /> <item android:state_focused="true" android:drawable="@drawable/tab" /> </selector>
source share