Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created October 16, 2015 19:56
Show Gist options
  • Save sibelius/7ca0b757492ff6740dec to your computer and use it in GitHub Desktop.
Save sibelius/7ca0b757492ff6740dec to your computer and use it in GitHub Desktop.
Custom Action Provider to show just a submenu to a menu item
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item android:id="@+id/action_companies"
android:icon="@drawable/ic_list"
android:title="@string/action_companies"
app:actionProviderClass="com.example.MyActionProvider"
app:showAsAction="always"/>
</menu>
public class MyActionProvider extends ActionProvider {
private Context mContext;
public MyActionProvider(Context context) {
super(context);
mContext = context;
}
@Override
public View onCreateActionView() {
//LayoutInflater layoutInflater = LayoutInflater.from(mContext);
return null;
}
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
super.onPrepareSubMenu(subMenu);
subMenu.clear();
subMenu.add("menu 1");
subMenu.add("menu 2");
subMenu.add("menu 3");
}
@Override
public boolean hasSubMenu() {
return true;
}
@Override
public boolean onPerformDefaultAction() {
return super.onPerformDefaultAction();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment