Skip to content

Instantly share code, notes, and snippets.

@gerits
Created October 13, 2014 05:58
Show Gist options
  • Save gerits/b37535fa3cace1252797 to your computer and use it in GitHub Desktop.
Save gerits/b37535fa3cace1252797 to your computer and use it in GitHub Desktop.
Material Design Overflow Menu
final ImageButton button = (ImageButton) findViewById(R.id.filter_overflow);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(context, findViewById(R.id.overflow_position));
menu.inflate(R.menu.default);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// handle menu actions
return false;
}
});
menu.show();
}
});
<LinearLayout
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:weightSum="1">
<View
android:id="@+id/overflow_position"
android:layout_width="56dp"
android:layout_height="0dp"
android:layout_weight="0" />
<ImageButton
android:id="@+id/filter_overflow"
android:layout_width="56dp"
android:layout_height="match_parent"
android:background="@drawable/selectable_background"
android:src="@drawable/ic_action_more_vert" />
</LinearLayout>
<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:listViewStyle">@style/ListView.CustomTheme</item>
</style>
<style name="ListView.CustomTheme" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:background">@android:color/white</item>
<item name="android:divider">@android:color/transparent</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment