In TabHost, when using setIndicator (String, Drawable), everything is as expected , the second element is selected and highlighted.
,
but with setIndicator (View), the previously created view is substituted but there is no indication of a choice (the first element is selected ). 
Tell me how to correct the situation and how to substitute your image instead of highlighting (tab is not selected - one image, tab is selected - another)
|
1 answer
First you do the selector:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Active tab --> <item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" /> <!-- Inactive tab --> <item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" /> <!-- Pressed tab --> <item android:state_pressed="true" android:drawable="@android:color/transparent" /> <!-- Selected tab (using d-pad) --> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@android:color/transparent" /> </selector> tab_bg_selected.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#A8A8A8" android:centerColor="#7F7F7F" android:endColor="#696969" android:angle="-90" /> </shape> tab_bg_unselected.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#5C5C5C" android:centerColor="#424242" android:endColor="#222222" android:angle="-90" /> </shape> Then in the code:
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); And on the first question, you probably used TabHost with the viewpager, for example, then it is enough to switch the page in the viewPager and then the tabhos will change to the following.
- Thanks for the hint, sort of figured out how to use the selector, but did not understand whether it was possible to change not the background, but the image. - x555xx
- @ x555xx If the answer helped, please mark the message as a solution, according to the rules of stackOverFlow. - Evgeny Suetin
|