Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add menu button without action bar?

I'd like to add a menu button to the right top corner of my app and without action bar, like it is in Google Fit app on the screenshot below. Can anyone help me?

menu button without action bar

like image 891
dzikovskyy Avatar asked May 23 '15 20:05

dzikovskyy


People also ask

How do I add menu button to my toolbar?

This is going to be in res/menu/main_menu . Right click the res folder and choose New > Android Resource File. Type main_menu for the File name. Choose Menu for the Resource type.

How do I set up no action bar?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.

How will you replace a menu with action bar in Android?

To replace an app's default action bar with a Toolbar : Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar .


1 Answers

You can simply use PopupMenu, for example add the following to a button when clicked:

public void showPopup(View v) {     PopupMenu popup = new PopupMenu(this, v);     MenuInflater inflater = popup.getMenuInflater();     inflater.inflate(R.menu.actions, popup.getMenu());     popup.show(); } 

Kotlin

fun showPopup(v : View){    val popup = PopupMenu(this, v)    val inflater: MenuInflater = popup.menuInflater    inflater.inflate(R.menu.actions, popup.menu)    popup.setOnMenuItemClickListener { menuItem ->       when(menuItem.itemId){          R.id.action1-> {                        }          R.id.action2-> {           }       }       true    }    popup.show() } 

For more info, read Creating a Popup Menu : http://developer.android.com/guide/topics/ui/menus.html

like image 130
Musa Avatar answered Oct 04 '22 04:10

Musa