Issue
what I'm looking for is to make an options menu but without the ActionBar. In the Google music app I saw that they have a options menu sort of thing with no action bar. Below is a picture of what I was talking about in the Google music app.
Thank you in advance! :) src="https://i.imgur.com/GaajLB0.png" alt="googleplaymusicapp">
Solution
That's just a simple popop. You can do that on any view. Throw an icon on a view, like the overflow menu icone and set a click listener on it.
This example is a list of devices (smartphones) in a catalog. I populate the tag with an object so I know which one the user clicks on.
public void showDeviceMenu(View v) {
PopupMenu popup = new PopupMenu(this, v);
popup.inflate(R.menu.cart_device_menu);
DeviceTag tag = (DeviceTag) v.getTag();
final String groupId = tag.groupId;
final String sku = tag.sku;
final String productId = tag.productId;
SpannableStringBuilder text = new SpannableStringBuilder(tag.name);
text.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
popup.getMenu().findItem(R.id.menu_name).setTitle(text);
invalidateOptionsMenu();
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.duplicate_device:
duplicateDevice(sku, productId);
return true;
case R.id.update_device:
updateWirelessItemInCart(sku,groupId);
return true;
case R.id.delete_device:
removeItemFromCart(groupId);
return true;
default:
return false;
}
}
});
popup.show();
}
Answered By - Martin
Answer Checked By - Robin (JavaFixing Admin)