Detailed example of Android top (toolbar) search box implementation

Detailed example of Android top (toolbar) search box implementation

This article introduces the use of two kinds of searchview. One is that the input box and search results are not in the same activity, and the other is in the same activity. First, write the layout file of toolbar. The icon in toolbar defines a layout file implementation under the menu file

Example code:

Under the menu, there are only two sub nodes, item and group, which are not specifically introduced here. The function of actionviewclass is to make the item display form. We use the built-in search box here.

Then write the searchable. XML file under your XML file

Imeoptions is used to turn the Enter key of the keyboard into search. There are other options here. I won't introduce them. Actionsearch displays the Enter key as the search key.

Then implement it in activity. Here, you must first implement toolbar instead of posting code,

Then override this method to get searchview

Then create a new activity, which is the interface for processing search results, and name it searchresultactivity.

In this way, the searchcontent is the content you entered in the search box.

Next, configure the activity in the configuration file

The above is that the search box and search results are not in one activity.

If both methods remain unchanged in an activity, just configure the two in the acitivity with search box in the configuration file

design sketch:

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>