简体   繁体   中英

overflow actionbar menu android

i imported the library from here, inorder to use it as actionbar:

https://github.com/johannilsson/android-actionbar

however i didnt find how can i implement a overflow menu item?

for example, in actionbarsherlock this code to implement the overflow menu item is:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/root_menu"
    android:icon="@drawable/ic_menu_moreoverflow_normal_holo_light"
    android:showAsAction="always"
    android:title="More">
    <menu>
        <item
            android:id="@+id/menu_settings"
            android:icon="@drawable/ic_menu_settings_holo_light"
            android:showAsAction="never"
            android:title="Settings" />
        <item
            android:id="@+id/menu_about"
            android:icon="@drawable/ic_menu_info_details"
            android:showAsAction="never"
            android:title="About"/>
   </menu>
</item>
</menu> 

can someone help me with it? maybe the developer of this code can help me?

thanks alot

same way you can implement system actionbar menu. no need to use any lib or other just use this code for your menu and it will work for you and for generating your menu use oncreateoptionmenu/onprepareoptionmenu for example using with this code

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/root_menu"
    android:icon="@drawable/ic_menu_moreoverflow_normal_holo_light"
    android:showAsAction="always"
    android:title="More">
    <menu>
        <item
            android:id="@+id/menu_settings"
            android:icon="@drawable/ic_menu_settings_holo_light"
            android:showAsAction="never"
            android:title="Settings" />
        <item
            android:id="@+id/menu_about"
            android:icon="@drawable/ic_menu_info_details"
            android:showAsAction="never"
            android:title="About"/>
   </menu>
</item>
</menu> 

now inflate this menu in your activity/fragementactivity using oncreateoptionmenu/onprepareoptionmenu

here is the using of action menu

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case R.id.menu_settings:
        Toast.makeText(context,"Setting menu selected",Toast.SHORT_LENGTH).show();
        break;      
    case R.id.menu_about:
        Toast.makeText(context,"About menu selected",Toast.SHORT_LENGTH).show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM