如何从Android中的PlaceAutocompleteFragment中删除搜索图标

时间:2017-02-13 18:45:12

标签: android google-places-api

我正在使用PlaceAutocompleteFragment搜索地点。 下面是我的xml代码

<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" />

我想删除默认带有片段的搜索图标。

screenshot

5 个答案:

答案 0 :(得分:7)

您可以使用此单行获取搜索图标的引用:((View)findViewById(R.id.place_autocomplete_search_button)).setVisibility(View.GONE);

和此行获取EditText的引用:((EditText)findViewById(R.id.place_autocomplete_search_input))

答案 1 :(得分:2)

如果我们有2个autocompleteFragments,我们可以隐藏这样的图标:

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

答案 2 :(得分:1)

上述解决方案对我不起作用,因为我使用的是2.1.0

此版本的ID为:

搜索图标:places_autocomplete_search_button

清除图标:places_autocomplete_clear_button

编辑文本:places_autocomplete_search_input

因此,为了简单地使用它们,

autocompleteSupportFragment.getView().findViewById(R.id.places_autocomplete_search_button).setVisibility(View.GONE);

答案 3 :(得分:0)

不幸的是,不可能自定义PlaceAutocompleteFragment的外观,但是,它所做的只是启动PlaceAutocomplete活动以响应点击,使用适用于您的应用的UI非常容易复制其功能。< / p>

  1. 创建自定义片段(instructions)。
  2. 将您想要的UI元素添加到片段中。
  3. 将OnClickListener添加到启动自动完成活动(as described in the API docs)的UI元素中。

答案 4 :(得分:0)

这个问题有点老了,但是我留给以后的观众看。

当您有一个PlaceAutocompleteFragment时,@ rajat44的答案可以解决该问题,如果有多个,您可以这样做:

pacf.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
pacf2.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);