Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove search icon from PlaceAutocompleteFragment in Android

I am using PlaceAutocompleteFragment to search places. Below is my xml code

<fragment
android:id="@+id/place_source"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimary"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />

I want to remove search icon which by default comes with fragment.

screenshot

like image 442
Ritesh Avatar asked Feb 13 '17 18:02

Ritesh


4 Answers

You can use this single line to get the reference of search icon :((View)findViewById(R.id.place_autocomplete_search_button)).setVisibility(View.GONE);

and this line to get the reference of EditText: ((EditText)findViewById(R.id.place_autocomplete_search_input))

like image 83
rajat44 Avatar answered Oct 22 '22 00:10

rajat44


If we have 2 autocompleteFragments, we can hide the icons like this :

autocompleteFragment_from.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
autocompleteFragment_to.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
like image 37
T.For Avatar answered Oct 22 '22 01:10

T.For


The above solutions didnt work for me as I was using 2.1.0

The ID's for this version are :

Search Icon : places_autocomplete_search_button

Clear Icon : places_autocomplete_clear_button

Edit Text : places_autocomplete_search_input

So in order to use them simply,

autocompleteSupportFragment.getView().findViewById(R.id.places_autocomplete_search_button).setVisibility(View.GONE);
like image 22
Akash Sarkar Avatar answered Oct 21 '22 23:10

Akash Sarkar


This question is a bit old, but I'll leave this here for future viewers.

While @rajat44's answer solves it when you have one PlaceAutocompleteFragment, if you have multiple you can do this:

pacf.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
pacf2.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
like image 29
PLPellegrini Avatar answered Oct 21 '22 23:10

PLPellegrini