简体   繁体   English

如何隐藏Android应用程序工具栏中的搜索栏?

[英]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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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