I've been trying to add a functionality to my android application such that when I click a button, menu listing should be visible:
Here is my code:
menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.MainActivity" >
<item android:id="@+id/action_onthego_sentence"
android:title="settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
From the main activity, upon clicking a button, I do:
button.setOnClickListener( new View.OnClickListener()
{
@Override
public void onClick( View view )
{
runOnUiThread( new Runnable()
{
@Override
public void run()
{
openOptionsMenu();
}
} );
}
} );
What I need is:

As shown in the image, I'd like to see the menu is opened. Any suggestions please?
If you are using customized toolbar in your app, then the following way will be useful,
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toolbar.showOverflowMenu();
}
}, 500);
Hello Dear if you are using toolbar following code
toolbar.showOverflowMenu();
And other wise you can directly call
MainActivity.this.openOptionsMenu();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With