6

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

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
Ankit Srivastava
  • 354
  • 1
  • 5
  • 24

2 Answers2

4

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.

yushulx
  • 11,695
  • 8
  • 37
  • 64
2

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.

Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85