public class OnEditActionListener implements OnEditorActionListener
{
@Override
public boolean onEditorAction(TextView v, int actionId, android.view.KeyEvent event) {
if(actionId ==EditorInfo.IME_ACTION_UNSPECIFIED){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ShipContentSearch(false);
}
return false;
};
{
@Override
public boolean onEditorAction(TextView v, int actionId, android.view.KeyEvent event) {
if(actionId ==EditorInfo.IME_ACTION_UNSPECIFIED){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ShipContentSearch(false);
}
return false;
};
}
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/home_edit_bg"
android:id="@+id/home_search"
android:paddingLeft="5dp"
android:layout_marginRight="50dp"
android:drawablePadding="5dp"
android:hint="点击查询配件"
android:textColor="@color/black"
android:imeOptions="actionSearch"
android:singleLine="true"
/>
本文介绍了一种在Android应用中实现搜索功能的方法。通过定义一个`OnEditActionListener`监听器,当用户在搜索框中输入并按下搜索键时,能够隐藏软键盘并触发搜索操作。该实现涉及`InputMethodManager`的使用,并展示了具体的XML布局配置。
1万+

被折叠的 条评论
为什么被折叠?



