imeOptions 在 AutoCompleteTextView 中不起作用
imeOptions isn't working in an AutoCompleteTextView
我有麻烦了。我正在使用 Google Maps Api v2,我创建了一个基本的工具栏,就像在 Google Maps App 中一样。我上面有一个 AutoCompleteTextBox。
问题是当我按下 'DONE' 按钮时(当屏幕处于纵向模式时),actionId==0 和 KeyEvent==0,但是当我按下标记的操作按钮时(当屏幕处于横向模式时)它起作用了,但是 DONE 按钮不起作用。
在java我写的代码实现中:
autoCompleteTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
//Log.i("AutoCompleteTextView", "Evento onEditorAction ... ");
search();
handled = true;
}
Log.i("AutoCompleteTextView", "Evento onEditorAction ... " + actionId);
return handled;
}
});
在 XML 布局中我使用了:
<AutoCompleteTextView
android:id="@+id/autoText"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="48dp"
android:layout_marginBottom="6dp"
android:layout_marginRight="6dp"
android:gravity="bottom"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fontColorMenu"
style="@style/AutoCompleteTextViewAppTheme"
android:imeActionLabel="Buscar"
android:imeOptions="actionDone"
android:hint="Ingrese ciudad"
android:inputType="text"/>
所以我不知道出了什么问题,我正在使用 targetSdkVersion 22,我的 Moto G on Android Lollipop 并使用 Android Studio 1.1.0.
是的,你是对的。因为您使用的是自己的文本 "Buscar" 而不是默认的 "Done"。要解决您的问题,请更改 EditorAction 方法代码。
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == event.ACTION_DOWN) {
search();
handled = true;
}
return handled;
}
我有麻烦了。我正在使用 Google Maps Api v2,我创建了一个基本的工具栏,就像在 Google Maps App 中一样。我上面有一个 AutoCompleteTextBox。
问题是当我按下 'DONE' 按钮时(当屏幕处于纵向模式时),actionId==0 和 KeyEvent==0,但是当我按下标记的操作按钮时(当屏幕处于横向模式时)它起作用了,但是 DONE 按钮不起作用。
在java我写的代码实现中:
autoCompleteTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
//Log.i("AutoCompleteTextView", "Evento onEditorAction ... ");
search();
handled = true;
}
Log.i("AutoCompleteTextView", "Evento onEditorAction ... " + actionId);
return handled;
}
});
在 XML 布局中我使用了:
<AutoCompleteTextView
android:id="@+id/autoText"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="48dp"
android:layout_marginBottom="6dp"
android:layout_marginRight="6dp"
android:gravity="bottom"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fontColorMenu"
style="@style/AutoCompleteTextViewAppTheme"
android:imeActionLabel="Buscar"
android:imeOptions="actionDone"
android:hint="Ingrese ciudad"
android:inputType="text"/>
所以我不知道出了什么问题,我正在使用 targetSdkVersion 22,我的 Moto G on Android Lollipop 并使用 Android Studio 1.1.0.
是的,你是对的。因为您使用的是自己的文本 "Buscar" 而不是默认的 "Done"。要解决您的问题,请更改 EditorAction 方法代码。
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == event.ACTION_DOWN) {
search();
handled = true;
}
return handled;
}