1

Am using Actionbar with Tabs..I need to change the Action bar items and title depending on Tab selection.I can change the title but i cannot change the item's icon.

Because actionBar.setTitle() is defalut method. Like that there is no default method for icon and item change..Action Bar can be used in Activity not Fragment..How to handle this situation? Please help me

Am using below code..

public class ActionBarActivity extends Activity{

public static Context context;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.actionbar);
    ActionBar actionBar = getActionBar();
    actionBar.setTitle("Action Bar");
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.show();



    ActionBar.Tab aTab = actionBar.newTab().setText("A");
    ActionBar.Tab bTab = actionBar.newTab().setText("B");
    ActionBar.Tab cTab = actionBar.newTab().setText("C");

    Fragment aFragment = new aActivity();
    Fragment bFragment = new bActivity();
    Fragment bFragment = new cActivity();

    aTab .setTabListener(new MyTabsListener(aFragment));
    bTab.setTabListener(new MyTabsListener(bFragment));
    cTab.setTabListener(new MyTabsListener(cFragment));

    actionBar.addTab(aTab );
    actionBar.addTab(bTab);
    actionBar.addTab(cTab);


}

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu, menu);
        return super.onCreateOptionsMenu(menu);

 }
user1670564
  • 391
  • 2
  • 4
  • 12
  • Is there a reason you have a static reference to a Context? – dnkoutso Nov 29 '12 at 05:13
  • No..just i used it for Toast message display. Also If am using Activity then i can change the action bar menu items by using onCreateOptionsMenu(Menu menu) with inflater. But tab using fragment.. so i cannot achieve it..Help me – user1670564 Nov 29 '12 at 05:16

0 Answers0