我需要在设备的软键盘上做搜索按钮。我的代码:
XML 文件:
<EditText
android:id="@+id/searchText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="15sp"
android:hint="@string/search"
android:drawableLeft="@drawable/ic_btn_search"
android:singleLine="true"
android:drawablePadding="5dp"
android:imeOptions="actionSearch"
android:imeActionLabel="Search" android:layout_weight="1"/>
Java 文件:
searchFild = (EditText) findViewById(R.id.searchEditTxt);
searchFild.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
searchFild.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int arg, KeyEvent keyEvent) {
if(arg == EditorInfo.IME_ACTION_SEARCH) {
String searchString=searchFild.getText().toString();
searchBibles(searchString);
return true;
}
return false;
}
});
搜索按钮预设在键盘中,但点击后没有任何反应。arg 为零。它适用于 android 2.2,但不适用于 android 4