日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 键盘搜索按钮不收起键盘,android EditText 实现搜索框点击搜索隐藏键盘

發布時間:2025/6/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 键盘搜索按钮不收起键盘,android EditText 实现搜索框点击搜索隐藏键盘 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

布局:

android:id="@+id/search_input"

android:background="#00000000"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="match_parent"

android:layout_marginLeft="5dip"

android:layout_marginRight="3dp"

android:drawableLeft="@drawable/push_mail_search"

android:drawablePadding="5dp"

android:ellipsize="end"

android:hint="搜索"

android:imeOptions="actionSearch"

android:singleLine="true"

android:focusable="true"

android:paddingLeft="2dp"

android:maxLines="1"

android:textColorHint="@color/gray_btn_bg_color"

android:textColor="#222222"

android:textSize="15sp" />

這是我項目里的布局文件,想要讓EditText 顯示搜索,最主要是兩個配置:

android:imeOptions="actionSearch"

android:singleLine="true"

點擊搜索框隱藏鍵盤:

search_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {

@Override

public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

if (actionId == EditorInfo.IME_ACTION_SEARCH) {

// 當按了搜索之后關閉軟鍵盤

Utils.hideKeyboard(search_input);

return true;

}

return false;

}

});

這里用到的工具類

Utils.hideKeyboard(search_input);

如下:

/**

* 隱藏軟鍵盤

*

* @param context :上下文環境,一般為Activity實例

* @param view :一般為EditText

*/

public static void hideKeyboard(View view) {

InputMethodManager manager = (InputMethodManager) view.getContext()

.getSystemService(Context.INPUT_METHOD_SERVICE);

manager.hideSoftInputFromWindow(view.getWindowToken(), 0);

}

輕松實現搜素,并且點擊隱藏鍵盤。

總結

以上是生活随笔為你收集整理的android 键盘搜索按钮不收起键盘,android EditText 实现搜索框点击搜索隐藏键盘的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。