0

I'm developing a android app with Action Bar Sherlock library, it runs normal on my device with api 17, "image 1", but on api 8 I'm getting the old menu style on itens out of action bar, "image 2", as follow my menu code:

Menu XML file:

<item
    android:id="@+id/menu_main_filter"
    android:alphabeticShortcut="@string/action_filter_shortcurt"
    android:icon="@drawable/ic_action_filter"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action_filter"/>
<item
    android:id="@+id/menu_main_share"
    android:alphabeticShortcut="@string/action_share_shortcurt"
    android:icon="@drawable/ic_action_share"
    android:orderInCategory="101"
    android:showAsAction="ifRoom"
    android:title="@string/action_share"/>
<item
    android:id="@+id/menu_main_about"
    android:alphabeticShortcut="@string/action_about_shortcurt"
    android:icon="@drawable/ic_action_about"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action_about"/>

<group
    android:id="@+id/menu_main_group_display_settings"
    android:checkableBehavior="single"
    android:orderInCategory="1000" >
    <item
        android:id="@+id/menu_main_use_indian_numbers"
        android:alphabeticShortcut="@string/action_use_indian_numbers_shortcurt"
        android:icon="@drawable/ic_action_indian"
        android:orderInCategory="10001"
        android:showAsAction="ifRoom"
        android:title="@string/action_use_indian_numbers"
        android:titleCondensed="@string/action_use_indian_numbers_condensed"/>
    <item
        android:id="@+id/menu_main_use_arabic_numbers"
        android:alphabeticShortcut="@string/action_use_arabic_numbers_shortcurt"
        android:icon="@drawable/ic_action_arabic"
        android:orderInCategory="10002"
        android:showAsAction="ifRoom"
        android:title="@string/action_use_arabic_numbers"
        android:titleCondensed="@string/action_use_arabic_numbers_condensed"/>
</group>

Activity java code:

public class MainActivity extends AbstractNombrojActivity {

private ListView listView;
private ListMainAdapter<Nombro> listMainAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listView = (ListView) findViewById(R.id.main_listview);
    listMainAdapter = new ListMainAdapter<Nombro>(getApplicationContext());
    listView.setAdapter(listMainAdapter);
    listView.setEmptyView(findViewById(R.id.main_listview_emptyview));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.main, menu);
    NombrojPreferences preferences = new NombrojPreferences(getApplicationContext());
    for (int c = 0; c < menu.size(); c++) {
        MenuItem menuItem = menu.getItem(c);
        if (menuItem.getItemId() == R.id.menu_main_use_indian_numbers && preferences.getNumberAlgarism() == NumbersAlgarism.Indian)
            menuItem.setChecked(true);
        if (menuItem.getItemId() == R.id.menu_main_use_arabic_numbers && preferences.getNumberAlgarism() == NumbersAlgarism.Arabic)
            menuItem.setChecked(true);
    }
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_main_use_indian_numbers:
        new NombrojPreferences(getApplicationContext()).setNumberAlgarism(NumbersAlgarism.Indian);
        invalidate();
        return true;
    case R.id.menu_main_use_arabic_numbers:
        new NombrojPreferences(getApplicationContext()).setNumberAlgarism(NumbersAlgarism.Arabic);
        invalidate();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

// custom
private void invalidate() {
    supportInvalidateOptionsMenu();
    listMainAdapter.notifyDataSetChanged();
}

My Aplication Theme:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

On values:

<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>
<style name="AppTheme" parent="AppBaseTheme"></style>

On values-v11:

<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>

And values-v14:

<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"></style>

What can causing this wrong behavior?


image 1:

menu on api 17

image 2:

meni on api 8

Thanks a lot!

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
ademar111190
  • 14,215
  • 14
  • 85
  • 114

2 Answers2

0

This is the standard implementation of the ActionBar for backwards compatibility since in api 8 the devices had a menu button and that was the standard. It helps keep platforms in standards (whether that is to be the old standard).

JRomero
  • 4,878
  • 1
  • 27
  • 49
  • thanks for answer but my device with api 17 have menu button too, is a galaxy 1. the problem isn't the menu button or overflow action button, the problem is the layout. I want the list like api 11> and not the menu squares like old api... – ademar111190 Aug 15 '13 at 17:15
  • This is how they decided to implement the ActionBar support library (both Sherlock and support libs) so that the applications stay within their platform expected functionality. There would be no easy solution for this unless you implement your own actionbar and implement `PopupMenu`s yourself. – JRomero Aug 15 '13 at 17:22
  • You can technically do so hackery and implement a manual overflow item with the existing ActionBar libs that when clicked you display a `PopupMenu` under the overflow item icon (top right corner). – JRomero Aug 15 '13 at 17:23
  • But action bar sherlock have the menu overflow support, see on image as follow: http://wptrafficanalyzer.in/blog/wp-content/uploads/2012/07/actionbar_menu_sherlock_mainactivity.png. – ademar111190 Aug 15 '13 at 17:27
  • Not for older devices, see https://groups.google.com/forum/#!topic/actionbarsherlock/6bx3aIbSUZg Later ForceOverflow was removed: http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock – JRomero Aug 15 '13 at 17:32
  • Understood, but what I want is not the overflow action button, if you see my image 1, from my device, it have no overflow button on action bar, the menu was opened with hardware menu button, and there, the menu showed is a list, in other way, the emulator with api 8 show a menu of native api 8. So if is for be on plataform standarts, why use the action bar? a starndart of api 11>... – ademar111190 Aug 15 '13 at 17:40
0

After a long search really it seems have no solution, because Android support Library and Action Bar Sherlock Library will use the old menu on old devices like the J.Romero said. So I did it, I create a fork from ActionBarSherlock and I'm using a customized version basead on ActionBarSherlock version 4.1.0 and using the theme "@style/Theme.Sherlock.[ANY].ForceOverflow", in my case "@style/Theme.Sherlock.Light.DarkActionBar.ForceOverflow". So it's all, works perfectly.

Detail, I not recommend use my version because it have no support and any bug solved or new feature of ActionBarSherlock version 4.2.0 or later will not show there!

here my fork

and bellow the new screenshots after solution :D

Api 8:

old device

Api 17:

new device

Community
  • 1
  • 1
ademar111190
  • 14,215
  • 14
  • 85
  • 114