我正在开发一个应用程序,其中我有四个选项卡。我希望在单击每个选项卡时,操作栏应该改变。现在我已经给出了操作栏标题、搜索栏和溢出图标。但我想在选择时更改操作栏每个选项卡,以便我可以根据选择相应选项卡的要求在操作栏中添加图标。
这是我的 ontabselection 代码,请建议我能做什么。任何帮助都是可以接受的。
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
FragmentTransaction fragMentTra;
if (tab.getText().equals("DEALS")) {
try {
rl.removeAllViews();
} catch (Exception e) {
}
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle("Deals");
FragmentDeals Fram1 = new FragmentDeals();
//fragMentTra.addToBackStack(null);
fragMentTra = getFragmentManager().beginTransaction();
fragMentTra.add(rl.getId(), Fram1);
fragMentTra.commit();
}
else if (tab.getText().equals("ORDER")) {
try {
rl.removeAllViews();
} catch (Exception e) {
}
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle("Order");
FragmentOrder Fram2 = new FragmentOrder();
//fragMentTra.addToBackStack(null);
fragMentTra = getFragmentManager().beginTransaction();
fragMentTra.add(rl.getId(), Fram2);
fragMentTra.commit();
}
else if(tab.getText().equals("CART")){
try {
rl.removeAllViews();
} catch (Exception e) {
}
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle("Shopping Cart");
FragmentCart fram3 = new FragmentCart();
//fragMentTra.addToBackStack(null);
fragMentTra = getFragmentManager().beginTransaction();
fragMentTra.add(rl.getId(), fram3);
fragMentTra.commit();
}
else if(tab.getText().equals("HISTORY")){
try {
rl.removeAllViews();
} catch (Exception e) {
}
ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setTitle("History");
FragmentHistory fram4 = new FragmentHistory();
//fragMentTra.addToBackStack(null);
fragMentTra = getFragmentManager().beginTransaction();
fragMentTra.add(rl.getId(), fram4);
fragMentTra.commit();
}
}
谢谢。