I have a video player app where you can search for videos. My video player is just a View I hide and show whenever the user is actually playing a video.
I implemented Search as a SearchView menu item that feeds a fragment. When you click on a video, the video player view will show up and play such video. If you press then the back button, the video player should be closed.
Instead, Android is taking my back press as the trigger to collapse the searchview on the action bar first, then on a second press I am able to catch the onBackPressed method on my activity to close the video.
How can I hook up before the action is collapsed, so I can disable it and close my video player on the first click?
I think the correct way to do this would be to add MenuItem.OnActionExpandListener
to your SearchView
item.
like so:
searchMenuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// return true if the item should collapse, false if collapsing should be suppressed.
return false;
}
});
You can view the official interface class reference here
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