How can you make this drop-down menu in the upper right corner. Does anyone have any lessons on this topic?

How can you make this drop-down menu in the upper right corner

Place Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); I want to realize what I wrote @katso

 @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_filter: Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); } 

    1 answer 1

    popup_menu.xml

     <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/one" android:title="One"/> <item android:id="@+id/two" android:title="Two"/> <item android:id="@+id/three" android:title="Three"/> </menu> 

     Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(MainActivity.this, button); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Toast.makeText(MainActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show(); return true; } }); popup.show(); } }); 
    • I need to write it here, but it seems that such methods have already tried @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_filter: Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_filter: Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_filter: Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); } - Satanist Devilov
    • instead of Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); - Satanist Devilov
    • I went clearer wrote. - Satanist Devilov
    • @SatanistDevilov, not clear) explain what you want to do - katso
    • Well, all the same by clicking on the icon. only the icon is registered in the Menu item list and by clicking on it so that the drop-down menu is called up. The cases are described above and in the case R.id.menu_filter: ........ return true; I want to process the drop-down menu by clicking. - Satanist Devilov