3

I have an android app with Navigation drawer and place AutoComplete fragment. Here is my current UI

Current UI

Now I can reveal the navigation drawer by swipe finger from left edge of the screen.But for user experience, I'd like to add an menu button in the search bar.

I want it to be the official google map app which has a place autocomplete fragment and a menu button in it. Also, I want to replace the microphone icon by search icon.

Google Map ui

For now, I have replace the searchIcon by menu icon by using following code

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    View childView=(LinearLayout) autocompleteFragment.getView();
    ImageView searchIcon=(ImageView) childView.findViewById(R.id.place_autocomplete_search_button);
    searchIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_black_24px));

    searchIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //TODO: how to reveal the navigation drawer
        }
    });

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO:Get info about the selected place.
            Log.i("AUTO", "Place: " + place.getName());
        }

        @Override
        public void onError(Status status) {
            // TODO:Handle the error.
            Log.i("AUTO", "An error occurred: " + status);
        }
    });

Here are my question now:

1.How to add a searchIcon to the right side of the search bar.(i.e how to write a custom UI for place AutoComplete fragment)

2.How to reveal the navigation drawer by click the menu button. What should I include in the onClick method?

Thanks a lot

rohitanand
  • 710
  • 1
  • 4
  • 26
Weijia Sun
  • 31
  • 3

1 Answers1

0

It's a late answer but maybe it will help for other pepole

// set icon as hamburger icon
 val imageView: ImageView? = autocompleteFragment.view?.findViewById(
            com.google.android.libraries.places.R.id.places_autocomplete_search_button
  )

 imageView?.let{
            it.setImageDrawable(resources.getDrawable(R.drawable.hamburger_icon))
            imageView.setOnClickListener{
                Toast.makeText(activity,"sdds",Toast.LENGTH_LONG).show()
         }
blay
  • 464
  • 9
  • 23