I have used a search widget in my app. I wanted to bring it in front of everything and I did it and tested it on real device. It worked fine. But when I tested it on a lollipop device, it didn't work. I then came to know that bringToFront()
doesn't work well in Lollipop. So I can use setElevation()
or something else(maybe setZ). But, I want to work it on every android device starting from API 17 to the latest version. How do I do that?
I am pasting my code below.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MaterialSearchView searchView = (MaterialSearchView) view.findViewById(R.id.search_view); //Search experiment
inflater.inflate(R.menu.toolbar_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
MenuItem item = menu.findItem(R.id.search_top);
searchView.setMenuItem(item);
searchView.bringToFront();
}