Monday, 24 October 2016


A popup menu shows a rundown of things in a vertical rundown that is secured to the view that conjured the menu. It's useful for giving a flood of activities that identify with particular substance or to give choices to a second part of a summon. Activities in a popup menu ought not specifically influence the relating substance—that is the thing that relevant activities are for. Or maybe, the popup menu is for stretched out activities that identify with areas of substance in your action.

Example :-
               PopupMenu ppm = new PopupMenu(this,view);

Code for PopupMenu in android.

activity_main.xml :-

<?xml version="1.0" encoding="utf-8"?> 
 android:layout_gravity="center_horizontal" />

popup_menu.xml :-

<?xml version="1.0" encoding="utf-8"?> 

</menu> :-

package com.kiranapp;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
public class MainActivity extends Activity {
    Button popupbtn;

 protected void onCreate(Bundle savedInstanceState) {

 popupbtn = (Button) findViewById(;
 popupbtn.setOnClickListener(new OnClickListener() {

 public void onClick(View v) {

 PopupMenu popup = new PopupMenu(MainActivity.this, popupbtn);
 popup.getMenuInflater().inflate(, popup.getMenu());
 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
 public boolean onMenuItemClick(MenuItem item) {
 Toast.makeText(MainActivity.this,"Click menu:" + item.getTitle(),
 return true;

Output :-

PopupMenu 1
PopupMenu fig :1

PopupMenu fig :2

PopupMenu fig :3

1 comment: