0

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

4

1 回答 1

0

同样的方式你可以实现系统操作栏菜单。无需使用任何库或其他只需将此代码用于您的菜单,它将为您工作并生成您的菜单使用 oncreateoptionmenu/onprepareoptionmenu 例如使用此代码

<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> 

现在使用 oncreateoptionmenu/onprepareoptionmenu 在您的活动/片段活动中扩展此菜单

这是操作菜单的使用

@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);
}
于 2013-03-26T12:54:36.237 回答