I need to display either the "reload" button in the actionBar or the "home" button, depending on the current activation. I will illustrate: alt text

How to add a separate home button - learned (using actionBarSherlock) It remains to figure out how to show / hide the reload button. It is impossible to do this in onCreateOptionsMenu just by getting the desired button by id - an error crashes. I have /menu/menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/reload_button" android:icon="@android:drawable/ic_menu_rotate"> </item> 

And another question is how to make the text be in the middle of actionBar.

    1 answer 1

    1) Show / hide the reload button:

     MenuItem menuItem; ... @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); menuItem = menu.findItem(R.id.reload_button); return true; } 

    And then use:

     menuItem.setVisible(false); 

    2) For the text to be in the middle, you need to make your layout as a custom view of the actionBar

     actionBar.setCustomView(); 
    • 1) And where should I call menuItem.setVisible (false)? 2) Custom actionbar action bar - what's this? - Stas0n
    • 1) in the part of the code where you want to show / hide this menu item 2) this means that you are doing a certain LinerLayout which is supposed to be a TextView and paste into> actionBar.setCustomView (R.layout. * Custom_layout *); - tim_taller 2:53 pm
    • Is it possible to zadad show / hide some elements in this custom view? - Stas0n