Gabriel Muniz Antonio
Gabriel Muniz Antonio

Reputation: 31

Android Search similar to Facebook's

I would like to build a search similar to facebook's app for Android, this means:

A search bar inside the action bar like this image: Facebook search

When the user touches the searchbar, the app shows a back arrow, a search field and the a list of suggestions, like this image:Facebook suggestions before typing

I have already used searchView.setIconifiedByDefault(false) to make the search bar appear always open, but how can I make the back button appear and open a different "page" with some suggestions, instead of the current page (that is a map)?

Sorry that I couldn't post the actual images, just the links, but I'm a beginner and don't have enough reputation yet.

Hope I could explain my question and that someone can give me a help!

Thanks!

Upvotes: 1

Views: 1213

Answers (1)

Brian Attwell
Brian Attwell

Reputation: 9299

There are a couple sub problems that you need to solve in order to get the behavior you want.

open a different "page" with some suggestions, instead of the current page (that is a map)?

First off, looks like you need a basic tutorial on implementing a search interface.

but how can I make the back button appear and open a different "page" with some suggestions?

Add a OnClickListener to the SearchView. When the SearchView is clicked, add a regular Button to your view hierarchy. Animate the Button into view using a property animation.

Do not try and perform animations with ActionBar's existing "Up Button". It is not designed to be animated. You need to add a regular Button. And as a result, you need to be able to add custom views into your ActionBar.

You can add custom views into the ActionBar by performing the following steps

  1. disabling android:contentInset inside the styles.xml
  2. ActionBar#setDisplayShowCustomEnabled(true)
  3. ActionBar#setCustomView(customContainerView)
  4. Be careful to make sure your custom view doesn't have a width of 0

The Button goes inside the customContainerView. For simplicity, I would probably put my SearchView into customContainerView as well so I can easily manage layout weights.

Upvotes: 1

Related Questions