Reputation: 364
hello guys here is the image of my context menu but i don't know how i can customize its view ??
i created context menu by using this code
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{//local=v;
super.onCreateContextMenu(menu, v, menuInfo);
info = (AdapterContextMenuInfo) menuInfo;
menu.add(Menu.NONE, v.getId(), 0, "Play");
menu.add(Menu.NONE, v.getId(), 0, "Queue song");
menu.add(Menu.NONE, v.getId(), 0, "Edit tags");
menu.add(Menu.NONE, v.getId(), 0, "Set as ringtone");
menu.add(Menu.NONE, v.getId(), 0, "View details");
menu.add(Menu.NONE, v.getId(), 0, "Delete");
}
but i wan't my menu to look like the one below ............. i wan't to know how i can change the color etc of the context menu??also the purple line that appear's,is that a nine patch image???
Upvotes: 6
Views: 17057
Reputation: 12160
You can use AlertDialog
to implement any custom context menu. create custom style view by
AlertDialog.Builder.setCustomTitle(View customTitleView) & AlertDialog.Builder.setView(View view)
You can listen to the long press event, and popup this dialog.
Upvotes: 4
Reputation: 16162
I am confuse with your question little bit , correct me if i am wrong,
Case 1 : You just want to set Title as second image you pasted. For that you have to just setTitle()
like menu.setHeaderTitle("Select Option");
,
So, Whole code should be like this ,
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{//local=v;
super.onCreateContextMenu(menu, v, menuInfo);
info = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("Select Option");
menu.add(Menu.NONE, v.getId(), 0, "Play");
menu.add(Menu.NONE, v.getId(), 0, "Queue song");
menu.add(Menu.NONE, v.getId(), 0, "Edit tags");
menu.add(Menu.NONE, v.getId(), 0, "Set as ringtone");
menu.add(Menu.NONE, v.getId(), 0, "View details");
menu.add(Menu.NONE, v.getId(), 0, "Delete");
}
Case 2: You are asking about some other Themes.In that case you should use other context menu theme.
Case 3 : You totally want to change UI , and want to make own UI. In that case you should have to create custom dialog and use as Context Menu.
Upvotes: 2