tabs - android tabHost -
I have 2 questions about tabhost: I've created tabs with 2 tabs, and I use setindicator (textview) for tab title. (I work with API level 4) My title background is white I use the selector to select between different images for the title.
-
I want to bold when the title text is only selected / pressed. I did not succeed in using this my selector Can I do it at all? The idea is that in the cases I use drawables, I want to bold the text. Other cases are not bold
-
It looks like a bug - when the tab opens first, the text on the selected tab (which I used in tabHost.setCurrentTab (tabId) Was not seen at all) It looks good after pressing / focus / focusing any other item
New TextView (Main Activity. Trust Inses (), Blank, Android. Gafix. Tapeface Normal); TextView title2 = new textview (Main activity. Trust incidents (empty, Android, graphics.Typeface.NORMAL); Title1.setText ("teb11 title"); Title1.setBackgroundResource (R.drawable.tabtitle); Title1.setCompoundDrawablesInternationalBounds (getResources (.) GetDrawable (R.drawable.tab1), empty, null, void); Title2.setText ("Tab 22 Title"); Title2.setBackgroundResource (R.drawable.tabtitle); Title2.setCompoundDrawablesWithIntrinsicBounds (getResources (). GetDrawable (R.drawable.tab2), empty, empty, zero); TabCpEC Tab 1 = MTAbHost. NEETBSPC ("Tab 1"). Setindicator (title1) .setContent (R.id.list1); TabCpEC Tab2 = MTB Host NEETBSPC ("Tab2"). Set indicator (title 2) .setContent (R.id.list2); MTabHost.addTab (tab1); MTabHost.addTab (tab2); MTabHost.setCurrentTab (0);
Selector tab 1.xml
& lt; Selector xmlns: android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Android Android: state_selected = "true" android: drawable = "@drawable / iconselected" /> & Lt; Item android: state_pressed = "true" Android: drawable = "@ drawable / iconselect" /> & Lt; Item Android: Drauble = "@ Drable / Icon" /> & Lt; / Selector & gt;
Tabulator selector
& lt; Selector xmlns: android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item android: state_pressed = "true" Android: drawable = "@ drawable / tabselected" /> & Lt; Item Android: state_selected = "true" android: drawable = "@ drawable / tab" /> & Lt; Item Android: state_focused = "true" android: drawable = "@ drawable / tab" /> & Lt; / Selector & gt;
For your Question # 1: On your tab The page selected (int position) on the code> Usage
like this:
Public zero selected (int position) on the page {// Your argument here fixTitleText () ; }
and:
Private Waste Fixitetext () (for (int i = 0; i & lt; mTabHost.getTabWidget (). GetChildCount ( ); I ++) {View View = mTabHost.getTabWidget (.) GetChildAt (i); TextView TV = (TextView) view.findViewById (android.R.id.title); tv.setTextColor (.getResources () getColor ( R.drawable.text_selector); Tv.setTextSize (TypedValue.COMPLEX_UNIT_SP, 14); Tv.setTypeface (tap, typeface.BOLD);}}
Just notice that this code Honeycomb and for that, before the tab host view hierarchy is slightly different