public class MainActivity extends TabActivity implements OnCheckedChangeListener {
private RadioGroup mainTab;
private TabHost tabhost;
private Intent iHome;//首页
private Intent iCart;//购物车
private Intent iOpt;//设置
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//无窗体显示
setContentView(R.layout.main);
initTabHost();
}
/**
* 初始化Tab数据
*/
private void initTabHost(){
mainTab=(RadioGroup)findViewById(R.id.main_tab);
mainTab.setOnCheckedChangeListener(this);
tabhost = getTabHost();
iHome = new Intent(this, HomeActivity.class);
tabhost.addTab(tabhost.newTabSpec("iHome")
.setIndicator(getResources().getString(R.string.main_home), getResources().getDrawable(R.drawable.icon_1_n))
.setContent(iHome));
iCart = new Intent(this, CartActivity.class);
tabhost.addTab(tabhost.newTabSpec("iCart")
.setIndicator(getResources().getString(R.string.main_xy), getResources().getDrawable(R.drawable.icon_2_n))
.setContent(iCart));
iOpt = new Intent(this, OptionActivity.class);
tabhost.addTab(tabhost.newTabSpec("iOpt")
.setIndicator(getResources().getString(R.string.main_opt), getResources().getDrawable(R.drawable.icon_3_n))
.setContent(iOpt));
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId){//根据选择ID来显示相应的Tab
switch(checkedId){
case R.id.radio_button0:
this.tabhost.setCurrentTabByTag("iHome");
break;
case R.id.radio_button1:
this.tabhost.setCurrentTabByTag("iCart");
break;
case R.id.radio_button2:
this.tabhost.setCurrentTabByTag("iOpt");
break;
}
}
}
android RadioGroup与TabHost组合使用达到菜单效果
猜你喜欢
转载自sjljsw.iteye.com/blog/1876527
今日推荐
周排行