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

Android About 662 words

设置

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;
}
Views: 3,226 · Posted: 2019-04-09

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh