Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize the view of context menu in android?

Tags:

android

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");

    }

enter image description here

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???

enter image description here

like image 492
Ankit Srivastava Avatar asked Dec 26 '13 09:12

Ankit Srivastava


2 Answers

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.

like image 62
yushulx Avatar answered Oct 14 '22 12:10

yushulx


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.

like image 31
Chintan Khetiya Avatar answered Oct 14 '22 11:10

Chintan Khetiya