【问题标题】:Keyboard dismiss automatically when search a place using PlaceAutocompleteFragment in Google place API使用 Google Place API 中的 PlaceAutocompleteFragment 搜索地点时,键盘会自动关闭
【发布时间】:2017-11-27 06:43:21
【问题描述】:

如何在使用 PlaceAutocompleteFragment 搜索地点时自动关闭键盘

我正在开发一个 android 应用程序并使用 Google Places API 根据用户搜索显示一个地点列表。 我正在使用 Place Autocomplete(PlaceAutocompleteFragment) 来完成此操作。

【问题讨论】:

  • 你有一些代码吗?
  • 添加代码.......

标签: android android-fragments google-places-api


【解决方案1】:

以下是您可以在Utils class 中包含的静态方法,以便在需要时隐藏键盘。

您可以在搜索完成时或在需要时调用此方法

public static void hideKeyboard(Activity activity) {
    InputMethodManager imm =
            (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}

请注意imm.hideSoftInputFromWindow 可能会抛出NullPointerException 所以添加适当的错误处理来解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    相关资源
    最近更新 更多