我正在寻找的是制作一个选项菜单,但没有 ActionBar。在谷歌音乐应用程序中,我看到他们有一个没有操作栏的选项菜单之类的东西。下面是我在 Google 音乐应用程序中谈论的内容的图片。
提前致谢! :)
最佳答案
这只是一个简单的弹出窗口。您可以在任何 View 上执行此操作。在 View 上添加一个图标,例如溢出菜单图标,并在其上设置一个点击监听器。
此示例是目录中的设备(智能手机)列表。我用一个对象填充标签,这样我就知道用户点击了哪个。
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();
}
关于没有 ActionBar 的 Android 选项菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22995165/