大家好,我正在尝试将图标添加到上下文菜单中的项目列表中,当用户长按 ListView 项目时触发。
列表与上下文菜单一起显示良好,我似乎唯一遇到困难的是设置图标。这是我的上下文菜单 xml 文件。
<item android:id="@+id/delete_item" android:title="Delete" android:icon="@drawable/delete" />
<item android:id="@+id/edit_item" android:title="Edit" android:icon="@drawable/edit"/>
我唯一想知道的可能是图像尺寸,它们是否必须是特定尺寸?
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Options");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
最佳答案
查看此链接:
Add Context Menu Icon in android
Context menus do not support icons.
从上面的 SO 问题中,有一个库可以让你做类似的事情:
关于android - 将图标添加到上下文列表中的菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14350107/