WEB开发网
开发学院手机开发Android 开发 Android 的 Tab 与 TabHost 讲解 阅读

Android 的 Tab 与 TabHost 讲解

 2010-04-14 01:42:00 来源:WEB开发网   
核心提示:}if (tagString.equals(“Three”)) {myMenuSettingTag = 3;}if (tagString.equals(“Four”)) {myMenuSettingTag = 4;}if (myMenu != null) {onCreateOptionsMenu(myMenu);}}复

}

if (tagString.equals(“Three”)) {

myMenuSettingTag = 3;

}

if (tagString.equals(“Four”)) {

myMenuSettingTag = 4;

}

if (myMenu != null) {

onCreateOptionsMenu(myMenu);

}

}

复制代码

然后onCreateOptionsMenu(Menu menu) 方法中通过MenuInflater过滤器动态加入MENU

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// TODO Auto-generated method stub

// Hold on to this

myMenu = menu;

myMenu.clear();//清空MENU菜单

// Inflate the currently selected menu XML resource.

MenuInflater inflater = getMenuInflater();

//从TabActivity这里获取一个MENU过滤器

switch (myMenuSettingTag) {

case 1:

inflater.inflate(myMenuResources[0], menu);

//动态加入数组中对应的XML MENU菜单

break;

case 2:

inflater.inflate(myMenuResources[1], menu);

break;

case 3:

inflater.inflate(myMenuResources[2], menu);

break;

case 4:

inflater.inflate(myMenuResources[3], menu);

break;

default:

break;

}

return super.onCreateOptionsMenu(menu);

}

复制代码

⑩运行效果

上一页  1 2 3 4 

Tags:Android Tab TabHost

编辑录入:coldstar [复制链接] [打 印]
赞助商链接