Does anyone know how to add a listener to the action overflow menu button ( the three dots on the action bar )?
I would like to add elements dynamically to the overflow menu, and I can’t figure out how to do it.
Help please 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t.
You can try
invalidateOptionsMenu()at the point when you know that you want different menu choices than what you had set up previously. However, I have heard reports that this may not affect the action bar.If the “dynamic” aspect is based on fragments coming and going, have your fragments implement the option menu items (via overriding
onCreateOptionsMenu()and callingsetHasOptionsMenu(true)). Android will add and remove items based on the changing mix of fragments on the screen.