-1
我有3個菜單項和我的應用程序中的四個選項卡使用actionbarsherlock,最初我顯示所有菜單項,當我更改標籤2項應隱藏,但不知何故它不工作。下面是我的代碼無法隱藏Tabchanged上的菜單項
final static int action_refresh = 0;
final static int facebook = 1;
final static int twitter = 2;
final static int in = 3;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
_menuInstance = menu;
menu.add(1, facebook, 1, "facebook").setIcon(R.drawable.facebook).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(1, twitter, 2, "twitter").setIcon(R.drawable.twitter).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(1, in, 3, "in Disk").setIcon(R.drawable.in).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case facebook:
Toast.makeText(this, "Connect on facebook", Toast.LENGTH_SHORT).show();
return true;
case twitter:
Toast.makeText(this, "Connect on twitter", Toast.LENGTH_SHORT).show();
return true;
case in:
Toast.makeText(this, "Connect on Linkedin", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onTabChanged(int pageIndex, ActionBar.Tab tab, View tabView) {
resetVisibilityFields();
if (_menuInstance == null) {
hideAllActionItems(_menuInstance);
switch (pageIndex) {
case 0:
showFirstTabActionItems(_menuInstance);
break;
case 1:
showSecondTabActionItems(_menuInstance);
break;
case 2:
showThirdTabActionItems(_menuInstance);
break;
case 3:
showFourthTabActionItems(_menuInstance);
break;
}
}
}
我試圖隱藏我的第一個選項卡上的圖標如下
private void showFirstTabActionItems(Menu menu) {
if (menu != null && menu.size() == 2) {
menu.getItem(1).setVisible(false);
menu.getItem(3).setVisible(false);
_firstTabShowed = true;
}
}
,但它不是working.Any幫助表示讚賞。