I have a Listview with a ContextMenu, but when I setIcon for ContextMenu look like it doesn't work
public void onCreateContextMenu(ContextMenu menu , View v,
ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.context_menu_favorite)
.setIcon(android.R.drawable.btn_star);
}
Context menus do not support icons.
While the Android API does not allow for Icons in Context menus you can see many places where Android is using them. Long pressing your home screen is one good example.
I took the time to dig through the Launcher and AnyCut source and found that Google is using their own custom class that extends a BaseAdapter along with their own custom layout.
I was able to copy their class and layout almost exactly and use it in my own app to accomplish. The class if you want to search for it is called AddAdapter.java.
Enjoy!
This library allows you to have a context menu (implemented as
AlertDialog
) with icons using a standard XML menu.https://code.google.com/p/android-icon-context-menu/
check this one....
While the API doesn't support icons in Context Menu, but we can always fake it by inflating a Dialog with our own view that looks like context menu.
Copy-pasting the following files exactly will do the job:
MainActivity.java
ContextMenuItem.java
ContextMenuAdapter.java
context_menu_item.xml
listview_context_menu.xml
I did it by this way:
Reference screenshot:
Menu:
menu_patient_language.xml
Style:
style.xml:
Java code:
Hope this would help you sure.
Done