Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Android EditText 软键盘回车键变成搜索键

Android 大约 662 字

设置

xml中设置EditText的属性,并且设置inputType

android:inputType="text"
android:imeOptions="actionSearch"

设置监听,实现TextView.OnEditorActionListener接口

mSearch.setOnEditorActionListener(this);

实现onEditorAction方法

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            getInfoFromNet();
        }
        return true;
    }
    return false;
}
阅读 2928 · 发布于 2019-04-09

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批