简体   繁体   中英

How to hide the search bar in the toolbar of my Android application?

I have a search bar in the toolbar of my application. How to hide the search bar in the toolbar temporarily? I want to hide it by default and show the title of the activity in the toolbar. When I want to search, the application is able to show the search bar again. What is the solution of this situation?

searchView.setVisibility(View.GONE);
titleac.setVisibility(View.VISIBLE);

You can hide the search bar by setting it to be an icon by default. It will become an icon and the title of the activity can be shown in the toolbar. Later you can expand the icon to be the search bar again by clicking the icon and change it back to an icon by clicking the cross icon in the search bar.

searchView.setIconifiedByDefault(true);

Try

searchbar.setVisibility(View.VISIBLE); 

and

searchbar.setVisibility(View.INVISIBLE);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM