当前位置: 代码迷 >> 综合 >> 让键盘的右下方位“搜索”两个字
  详细解决方案

让键盘的右下方位“搜索”两个字

热度:76   发布时间:2023-10-15 10:36:18.0

1、亲,我试了很多次,每次TM居然都是回车键,最后一次碰巧我在xml里面写了一句代码就可以了,居然是 android:singleLine="true"   ;草。我以前试过很多次lines = 1.。。居然不可以,,,,搞得我都怀疑人生了,我其他做的跟网上别人的一模一样都没用。最后还是被我弄好了。我只想发表心里感受:草

<EditTextandroid:id="@+id/et"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="点我一下弹出键盘,再次点击键盘消失哦"android:imeOptions="actionSearch"android:singleLine="true" />

然后对软键盘进行监听:

EditText editText = (EditText) findViewById(R.id.et);editText.setOnEditorActionListener(new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId,KeyEvent event) {if (actionId == EditorInfo.IME_ACTION_SEARCH) {Toast.makeText(MainActivity.this, "1", Toast.LENGTH_SHORT).show();return true;// 返回true代表处理了事件}return false;}});


  相关解决方案