android将软键盘显示为搜索键

方法很简单,首先要在EditText的属性加入 android:imeOptions="actionSearch" ,这个属性的作用是启用软键盘时将回车键设置成搜索键, android:singleLine="true"这个也必须写!  不然没有作用哦 

然后就是监听搜索按钮点击事件了,代码如下:

EditText test=(EditText) findViewById(R.id.test);
        test.setOnEditorActionListener(new OnEditorActionListener() {
            
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                // TODO Auto-generated method stub
                Toast.makeText(XListViewActivity.this, "test", Toast.LENGTH_SHORT).show();
                return false;
            }
        });

代码很简单,记录下来省得以后忘了

posted @ 2014-05-26 21:54  其实我不懂编程  阅读(427)  评论(0编辑  收藏  举报