问题
I am following one book tutorial. While developing it, I come across a typical problem. I need to know that how should I change my content of a Tab while I move from one tab to another? thanks for any suggestions.
回答1:
Here is a nice tutorial of TabActivity you are looking for,
Tab Example
For changing the icon of selected tab you have to create an xml for each tab like this in drawable folder
first_tab.xml
<item android:state_selected="false"
android:drawable="@drawable/tab_unselected_icon"/>
<item android:state_selected="true"
android:drawable="@drawable/tab_selected_icon"/>
</selector>
And the while creating tabs you have to use this xml like this,
intent = new Intent().setClass(this, Activity_name.class);
spec = tabHost.newTabSpec("yourTab_name").setIndicator("yourTab_name",res.getDrawable(R.drawable. first_tab)).setContent(intent);
tabHost.addTab(spec);
And you are done with it. Thanks.
来源:https://stackoverflow.com/questions/7226268/how-to-change-content-of-a-tab-while-switching