Android. Drop-down menu by clicking on the icon
How can I make this drop-down menu in the upper right corner. Does anyone have any lessons on this topic?
In Place Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show();
, I want to implement what @katso wrote
@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);
}
2
Author: Satanist Devilov, 2016-09-14
1 answers
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();
}
});
1
Author: katso, 2016-09-14 16:06:22