Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarSherlock ForceOverflow resource not found

I upgraded to version 4.2 and found that my old code did not compile because it appears the ForceOverflow parent theme has been removed.

After Googling this issue it appears that the it was deliberately removed to maintain device consistent menu buttons.

I do understand the argument for using the physical menu button, but I just don't agree with it... plus it is so damn ugly those old menus.

I really don't want users saying they cannot access previous functionality (which after all is the reason the menus buttons were moved to be visible on screen), so what are my options here? Will this be changed in a future release? Do I have to stick with a previous version of ABS and deal with some other bugs in the old ABS libs which were fixed in recent versions? Is there any work around?

like image 873
timothyjc Avatar asked Oct 13 '12 17:10

timothyjc


1 Answers

Instead of trying to get a "real" overflow menu, we can fake it with a SubMenu.

It will look like and behave like the original overflow button, just better because it will always be there.

private Menu mainMenu;
private SubMenu subMenu1;

    @Override
public boolean onCreateOptionsMenu(Menu menu) {

    mainMenu = menu;

    subMenu1 = menu.addSubMenu("");
    subMenu1.add("Settings");
    subMenu1.add("About");
    subMenu1.add("Help");

    MenuItem subMenu1Item = subMenu1.getItem();
    subMenu1Item.setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_dark);
    subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}

Of course you can set the subMenus just as you did before. With groudID, itemID etc.

Note that I already choosed *ic_menu_moreoverflow_normal_holo_dark* as the menu icon. This way the button will also look like an overflow.

Now we just need this Submenu to open when the user pressed the hardware menu button. We can do this very easy if you set mainMenu and subMenu1 like i did before.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
            mainMenu.performIdentifierAction(subMenu1.getItem().getItemId(), 0);
            return true;
    }
    return super.onKeyUp(keyCode, event);
}

Beware that you import:

import com.actionbarsherlock.view.SubMenu;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

and not:

import android.view.MenuItem;
like image 74
Sorcerer Avatar answered Nov 16 '22 16:11

Sorcerer