Android Search Dialog Setting

After several searches, I could not figure out how to configure the search dialog (the top search bar that appears when you click the search button). I want to change the background color of the search bar. I got articles on how to customize the title bar. But this does not work for the search bar.

Any useful pointers please ...

+3
source share
2 answers

I found the Android Search Dialog , which is an amazing and customizable search dialog with built-in search options.

See demo image:

Tell me how - the place of Geekier technology We used a simple layout for a simple search dialog, but you can use something else and, in other words, you can do it your own way. Of course, your layout should have these two types:

  • Editing text to enter a search key
  • A RecyclerView to display results in it

If you just want to use a simple search dialog, you first need to provide searchable items. To do this, you must implement Searchable in your model.

public class SampleSearchModel implements Searchable { private String mTitle; public SampleSearchModel(String title) { mTitle = title; } @Override public String getTitle() { return mTitle; } public SampleSearchModel setTitle(String title) { mTitle = title; return this; } } 

Now generate some search parameters in your activity:

 private ArrayList<SampleSearchModel> createSampleData(){ ArrayList<SampleSearchModel> items = new ArrayList<>(); items.add(new SampleSearchModel("First item")); items.add(new SampleSearchModel("Second item")); items.add(new SampleSearchModel("Third item")); items.add(new SampleSearchModel("The ultimate item")); items.add(new SampleSearchModel("Last item")); items.add(new SampleSearchModel("Lorem ipsum")); items.add(new SampleSearchModel("Dolor sit")); items.add(new SampleSearchModel("Some random word")); items.add(new SampleSearchModel("guess who back")); return items; } 

Then you just need to add the following lines where you want to show the dialog:

 new SimpleSearchDialogCompat(MainActivity.this, "Search...", "What are you looking for...?", null, createSampleData(), new SearchResultListener<SampleSearchModel>() { @Override public void onSelected(BaseSearchDialogCompat dialog, SampleSearchModel item, int position) { Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }).show(); 

Hope this will be helpful!

+1
source

Source: https://habr.com/ru/post/889228/


All Articles