If you not understand this lecture Contextual Action mode in android studio.You should also read my previous lectures Option Menu in android studio and Creating a time picker in android . After reading these lecture you will also able to create Contextual Action mode of your app.


Contextual action mode displays a bar at the top of the screen with a items such Delete, share, etc.When a user enables this mode by selecting an item a contextual action bar appears at the top of the screen to present actions the user can perform on the currently selected item.


In this lecture  we  will describe how can create contextual action mode in android studio .And also describe what is contextual Action mode.why we can use it.After Reading this lecture you will understand Contextual action mode in android And i hope you will create Contextual action Mode of your application.

Contextual menu and Contextual action mode

Contextual menus used to select one option menu.Context Menu displays hierarchical data as a multi level menu in a popup.It provides option of items and user can select one option at a time.But the contextual action mode display action bar at the top and provide facility to user.User can select multipal items in contextual action mode.

Description of Contextual action mode

The contextual action mode is available on Android 3.0.Contextual option menu is used when you select multipal items.Using contextual action mode you will select multipal items at a same time.You can used contextual action mode for individual or selecting multipal option.Like a list of items in a list view or some image in a grid view.In this lecture will describe how can create contextual action mode with individual mode.So we create a new project in android studio.Every project contain two file first is java class file and second is layout XML file.So our first step is add image in drawable folder how can add image into drawable folder please read step 1.For more detail about contextual action mode please click on Contextual action mode.

Step 1=Image add<-copy image->and right click on drawable<-paste image>into<-drawable folder->

After this step you will create a new menu .how can create menu layout detail is provides step by step n a below pic.

Step 2=Add menu<-Right click the menu folder-><- select new option->and click on-<Menu resource folder->

Alt Tag android add  new menu.xml image



Alt tag android menu assign name menu

First of all we will add two items first item is for deleting the image and second item that are add is  for sharing the image So add these two items using< item> attributes. and also assign id and title to each item.For all menu types, Android provides a standard XML format to define menu items. Instead of building a menu in your activity code  you should define a menu and all its items in an XML.Code that are write in menu.xml file

After this step you will open a Layout.XML file.And add image and set height and width.And also need to assign id to image view using android id attribute.And use android src property to assign image.Code that are write in Layout. XML file

Code that are write MainActivity. java class file.

Run the Application of contextual action mode

Alt Tag android contextual action mode

When you long press in a pic that are show in emulator then this output will show

Alt Tag contextual action mode

Thank you  for reading this lecture Hope you got the idea.