Editetext获取焦点后让输入软键盘中出现搜索按键

要实现的效果如上图所示。注意在右下角出现了一个"搜索"的按钮。

1.首先为布局文件中的Editetext控件中添加 android:imeOptions="actionSearch"  属性。

2.在代码中监听搜索按钮。

mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // TODO Auto-generated method stub
        if(actionId == EditorInfo.IME_ACTION_SEARCH){
            search();
            return true;
        }
        return false;
    }
});

 

posted on 2014-10-15 14:53  刘豆  阅读(376)  评论(0编辑  收藏  举报

导航