如何在android软键盘上显示“搜索”作为文本而不是Serach图标

时间:2015-08-06 06:24:57

标签: android android-activity android-softkeyboard

如何在软键盘上用“搜索”文本替换搜索图标。

<EditText 
android:imeOptions="actionSearch" />

2 个答案:

答案 0 :(得分:2)

使用以下代码而不是使用imeOptions: -

<EditText android:imeOptions="actionSearch" 
         android:inputType="text"/>

对于处理点击监听器,请执行以下操作:

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
@Override 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        performSearch(); 
        return true; 
    } 
    return false; 
} }); 

答案 1 :(得分:1)

this stackoverflow问题中获取答案。

尝试设置

    XML中的
  • android:imeActionLabel
  • 在带有.setImeActionLabel()
  • 的java代码中

editText.setImeActionLabel(getString(R.string.xxx), EditorInfo.IME_ACTION_SEARCH);