How to remove search icon from PlaceAutocompleteFragment in Android

前端 未结 5 547
一整个雨季
一整个雨季 2021-01-14 03:45

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



        
相关标签:
5条回答
  • 2021-01-14 04:23

    It's not possible to customize the look of the PlaceAutocompleteFragment unfortunately but, since all it does is launch the PlaceAutocomplete activity in response to taps it's pretty easy to replicate its functionality with a UI that works for your app.

    1. Create a custom fragment (instructions).
    2. Add the UI elements you want to the fragment.
    3. Add an OnClickListener to the UI elements that starts an autocomplete Activity (as described in the API docs).
    0 讨论(0)
  • 2021-01-14 04:28

    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))

    0 讨论(0)
  • 2021-01-14 04:31

    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);
    
    0 讨论(0)
  • 2021-01-14 04:31

    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);
    
    0 讨论(0)
  • 2021-01-14 04:31

    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);
    
    0 讨论(0)
提交回复
热议问题