0

在此处输入图像描述

List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.LAT_LNG, Place.Field.ADDRESS, Place.Field.NAME);
    // Start the autocomplete intent.
    Intent intent = null;

    if (initialQuery != null && !initialQuery.isEmpty()) {
        intent = new Autocomplete.IntentBuilder(
                AutocompleteActivityMode.FULLSCREEN, fields).
                setInitialQuery(initialQuery).
                setTypeFilter(TypeFilter.CITIES).
                build(activity);
    } else {
        intent = new Autocomplete.IntentBuilder(
                AutocompleteActivityMode.FULLSCREEN, fields).
                setTypeFilter(TypeFilter.CITIES).
                build(activity);
    }

    activity.startActivityForResult(intent, GOOGLE_PLACES_PICKER_REQUEST_CODE);

上面的代码打开GooglePlacesPicker了我们可以搜索地点的地方。点击后退箭头应关闭键盘。但事实并非如此。

我尝试了以下方法来关闭键盘

   public static void hide(Context context) {
    try {
        if (context != null) {
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            if (((Activity) context).getCurrentFocus() != null) {
                View currentFocus = ((Activity) context).getCurrentFocus();
                if (currentFocus.getWindowToken() != null) {
                    imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.SHOW_FORCED);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

但没有奏效。好心的帮助

4

1 回答 1

1

像这样设置关闭键盘按钮

hideButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {

                        InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        in.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), 0);
                    }
    });
于 2020-02-12T06:41:55.677 回答