奇妙なバグがあります。
EditText があり、TextWatcher で検索を実行しています。3 文字以上を入力すると、検索が実行されます。
最近まで、私は通常の EditText を持っていました。キーボードに検索アイコンを表示したいので、コードに EditText を追加しました。
searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
今では検索アイコンがあり、今私の問題です。検索アイコンを押すと、キーボードを閉じるだけで済みます。検索は必要ありません。
ここに私のコードがあります:
searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH)) {
hideSoftKeyboard();
}
return false;
}
});
hideSoftKeyboard は、キーボードを閉じるメソッドで、内部のコードは次のとおりです。
public void hideSoftKeyboard() {
if (getActivity().getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
}
今、私のキーボードは閉じますが、何らかの理由で「通常の」キーボードがその後ろに表示されます。検索アイコンのあるキーボードは閉じていますが、入力アイコンのあるキーボードが表示され、何も入力していません..編集テキストなどに接続されていません。その画面には編集テキストが1つしかなく、わかりませんどうしたの。
IME_ACTION_DONE に戻すと、すべて正常に動作します。
編集1:
マニフェストでの私の活動:
<activity
android:name=".UI.activity.HomeActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
およびxmlの私のEditText:
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/search_document_main"
android:typeface="serif"
android:visibility="invisible"
android:singleLine="true"
android:background="@color/top_bar_bg_color"
android:hint="Search" />
私が間違っていることは何ですか?
また、imeOption Search を使用せずにその検索アイコンを表示する方法はありますか??