Android: Popup Menu
This representative uses a Basic Activity type app amongst a circular push (FloatingActionButton) that hovers over the bottom correct of the interface.
Creating the popup carte du jour
To practice the popup carte du jour it is necessary to outset instantiate together with thence add together items earlier adding a listener (OnMenuItemClickListener) to position the exceptional clicked. It is too necessary to know the stance from which the carte du jour volition originate.
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); end PopupMenu carte du jour = novel PopupMenu(this, fab); menu.getMenu().add("Add Image"); menu.getMenu().add("Add Text"); menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { world boolean onMenuItemClick(MenuItem item) { // insert your code hither Log.d("menu title: ", item.getTitle().toString()); provide true; } } );
Showing the carte du jour
The adjacent footstep is to attach an OnClickListener to the stance that is going to trigger the appearance of the popup menu. Here I purpose the floating activity push to which I attach an OnClickListener amongst the merely pedagogy on click that it volition demo the menu.
fab.setOnClickListener(new View.OnClickListener() { @Override world void onClick(View view) { menu.show(); } });This is all at that spot is to it, the code tin hand notice last placed inwards the onCreate method of your MainActivity for testing.
Comments
Post a Comment