In this tutorial, I am going to show how to create custom vertical dropdown icon menu in android programmatically. Creating and implementing custom menu is not so difficult in android because we can make such menu with XML and to make perfectly working we have to add little bit java code in our app activity file.

We can create and implement drop down icons menu in android only using one XML layout file and a java activity file. But to add some extra effect like animation, hover color, etc. we have to create some XML file in drawable folder or you can add some code in java activity file.

Here, you will learn not only to implement drop down custom icon menu in your android application but also learn to add onClick event to the icon and to add on press or focus color to the icon background.

Android Dropdown Menu Example
Android Spinner Example
Android Action Bar Tutorial and Example With Option Menu

Example: How to Implement Custom Vertical Dropdown Icons Menu in Android

Let’s start step by step implementing dropdown icon menu in android application. Following are the different XML and java file.

XML Layout File

Following is the XML layout file where I have added ImageButton and TextView inside LinearLayout and RelativeLayout with some important attributes.


Java Activity File

Following is the modified code of java activity file where I have added onClick event to show and hide dropdown icon menu.


For implementing on pressed color in icon background I have create onclick_press_color.xml file inside res/drawable directory. Following is the content of onclick_press_color.xml file.


And following is the colors.xml


Example: How to Implement Custom Vertical Dropdown Icons Menu in Android

That’s all. Now run your Android Custom Vertical Dropdown Icons Menu application and click dropdown button, which will look like the above screenshot.

Post a Comment

Powered by Blogger.