Description:
When you take a look at android sdk document on Context Menu, you would notice that current Context Menu does not support for Icon. But if you do a long click on the home screen of your phone, you would see something like the image below. So how google did that? This tutorial will guide you through the steps to archive something like that.
Creating Demo Application:
First of all, we will create a demo application on which our context menu will be displayed. The demo application is just a simple one which shows a list of items (using ListView), when you do a long click on an item, the Context Menu will appear. This is a simple application with only a ListView, so we will skip through this step.
Implement Context Menu:
I've looked through the code of Android Launcher Application, and realized that the application did not actually use Context Menu. It was implemented by using a dialog with a custom list view. So I decided to take this approach for the tutorial.
1. Create IconContextMenuItem:
This class will hold our menu item's information, including: menu title, menu icon, and menu id.
import android.content.res.Resources; import android.graphics.drawable.Drawable; public class IconContextMenuItem {