How to change content of a Tab while switching

人盡茶涼 提交于 2019-12-11 13:06:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!