android 关于EditText键盘监听、多行显示并监听

1、EditText多行显示

并且支持imeOptions设置,单行显示并且设置imeOptions很简单,条件是在xml中将singleLine设置为true, 将inputType设置为text,多行显示默认是不能设置,默认是回车键。

XML

android:inputType=”text|textCapSentences”

JAVA

editText.setHorizontallyScrolling(false); 
editText.setMaxLines(Integer.MAX_VALUE);

2、键盘的监听

在搜索时没有搜索按钮,而是调用软件盘上的按钮。调用的实现只需要在XML在输入框中加入android:imeOptions="actionSearch",另外,还要设置android:singleLine="true",保证点击不会换行,最后调用软键盘时,回车键就会显示搜索二字。然后调用 OnEditorActionListener,不是OnKeyListener。

searchPatient.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    String search = searchPatient.getText().toString().trim();
                    initCaseControl(search);
                    return true;
                }
                return false;
            }
        });
发布了49 篇原创文章 · 获赞 2 · 访问量 8614

猜你喜欢

转载自blog.csdn.net/yangjunjin/article/details/100035722
今日推荐