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();
}
}
但没有奏效。好心的帮助