ActivityGroup实现iPhone风格的底部tab菜单
public class ActsGroup extends ActivityGroup { private LinearLayout bodyView; private LinearLayout home, gamebox, team, more; private int flag = 0; // 通过标记跳转不同的页面,显示不同的菜单项 // private String parameter = Constant.BUTTON_HOME;// 初始化加载 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); // 无标题 super.onCreate(savedInstanceState); setContentView(R.layout.acts_group); initMainView(); // 主界面开始接收参数 Bundle bundle = getIntent().getExtras(); if (null != bundle) { flag = bundle.getInt("flag"); } // 默认显示 showView(flag); home.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub flag = 0; showView(flag); } }); gamebox.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub flag = 1; showView(flag); } }); team.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub flag = 2; showView(flag); } }); more.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub flag = 3; showView(flag); } }); } /* * 初始化主界面底部的功能菜单 */ public void initMainView() { bodyView = (LinearLayout) findViewById(R.id.bodyL); home = (LinearLayout) findViewById(R.id.home); gamebox = (LinearLayout) findViewById(R.id.gamebox); team = (LinearLayout) findViewById(R.id.team); more = (LinearLayout) findViewById(R.id.more); } // 在主界面中显示其他界面 public void showView(int flag) { switch (flag) { case 0: showHome(); break; case 1: showGamebox(); break; case 2: showTeam(); break; case 3: showMore(); break; default: break; } } public void showHome() { bodyView.removeAllViews(); bodyView.addView(getLocalActivityManager().startActivity("home", new Intent(ActsGroup.this, MainActivity.class)).getDecorView()); home.setBackgroundResource(R.drawable.tab_highlight); gamebox.setBackgroundResource(R.drawable.tab_background); more.setBackgroundResource(R.drawable.tab_background); team.setBackgroundResource(R.drawable.tab_background); } public void showGamebox() { bodyView.removeAllViews(); bodyView.addView(getLocalActivityManager().startActivity("gamebox", new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView()); gamebox.setBackgroundResource(R.drawable.tab_highlight); home.setBackgroundResource(R.drawable.tab_background); more.setBackgroundResource(R.drawable.tab_background); team.setBackgroundResource(R.drawable.tab_background); } public void showTeam() { bodyView.removeAllViews(); bodyView.addView(getLocalActivityManager().startActivity("team", new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView()); team.setBackgroundResource(R.drawable.tab_highlight); home.setBackgroundResource(R.drawable.tab_background); more.setBackgroundResource(R.drawable.tab_background); gamebox.setBackgroundResource(R.drawable.tab_background); } public void showMore() { bodyView.removeAllViews(); bodyView.addView(getLocalActivityManager().startActivity("more", new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView()); more.setBackgroundResource(R.drawable.tab_highlight); home.setBackgroundResource(R.drawable.tab_background); team.setBackgroundResource(R.drawable.tab_background); gamebox.setBackgroundResource(R.drawable.tab_background); } }
暂无评论