Reputation: 4408
I am using a custom toolbar which has a menu icon. Now on clicking this menu icon i want to show the options menu. How can this be done.
I tried adding a onclicklistener to this menu icon
@Override
public void onClick(View v) {
if(v.getId() == R.id.toolbarMenuIcon){
openOptionsMenu();
}
}
This didnt work. Then i added these lines
setSupportActionBar(mBinding.customSelectToolbar.selectionModeToolbar);
in my activitys oncreate() . Also did override
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.selection_mode_menu, menu);
return super.onCreateOptionsMenu(menu);
}
With this i can see the overflow menu when i click the icon. But the problem is that, it adds the default menu icon also to the tool bar and thus my tool bar has two menu now. How can i have only my custom toolbar icon open the options menu
Upvotes: 1
Views: 2609
Reputation: 4408
I got it working using theme
<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_menu_overflow</item>
<item name="android:tint">...</item>
<item name="android:width">..dp</item>
<item name="android:height">..dp</item>
</style>
<style name="OnArrival.toolbarTheme" parent="Theme.OnArrival.Light">
<item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>
Upvotes: 1
Reputation: 23881
If you want to customize the default overflow menu icon..
Use setOverflowIcon method of your toolbar.
like:
toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.your_icon));
Upvotes: 4