android 修改键盘enter图标,设置搜索等图标

android 软键盘可以通过设置 android:imeOptions来改变enter位置的图标,设置成搜索或者发送,下一个等等

有两种方法设置,一种是在xml里边,一种是在代码里边

如:xml中设置android:imeOptions="actionSearch",对应代码为: editTextSearch.setImeOptions(EditorInfo.IME_ACTION_SEND);

下边是常用的几个属性值

布局actionUnspecified  未指定,代码对应常量EditorInfo.IME_ACTION_UNSPECIFIED. 
布局actionNone 没有动作,代码对应常量EditorInfo.IME_ACTION_NONE
布局actionGo 去往,代码对应常量EditorInfo.IME_ACTION_GO
布局actionSearch 搜索,代码对应常量EditorInfo.IME_ACTION_SEARCH   
布局actionSend 发送,代码对应常量EditorInfo.IME_ACTION_SEND
布局actionNext 下一个,代码对应常量EditorInfo.IME_ACTION_NEXT 
布局actionDone 完成,代码对应常量EditorInfo.IME_ACTION_DONE

如果设置完成,发现无效,可以尝试在布局中设置两个属性

将singleLine设置为true, 将inputType设置为text
在代码中捕捉事件

 //设置弹出键盘输入完成图标为搜索,点击搜索事件
        editTextSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))

                {
                    if (mListener != null) {
                       //搜索事件等
                    }
                    return true;

                }
                return false;
            }
        });

    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值