To begin with, I have a fragment-based app. On the first fragment user sees recyclerview
and I'm calling onCreateOptionsMenu()
which makes menu with a searchview
. The problem is, when I switch to other fragments I also see this menu. And if another fragment has its own menu, inflater
adds items from both menus. As a result, I see my searchview
-icon everywhere. Can you please explain me, what am I doing wrong?
Try to override
onCreateOptionsMenu()
in all your fragments and call super.onCreateOptionsMenu()
before anything else. Alternatively , use menu.clear()
in those other fragments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.