当前位置: 移动技术网 > 移动技术>移动开发>Android > android:imeOptions属性详解以及无效处理

android:imeOptions属性详解以及无效处理

2020年07月27日  | 移动技术网移动技术  | 我要评论

一、键盘右下角的键设置

(1)actionUnspecified未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED效果:

(2)actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE效果:
(3)actionGo去往,对应常量EditorInfo.IME_ACTION_GO 效果:
(4)actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH效果:
(5)actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND效果:
(6)actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT效果:
(7)actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE效果:

android:imeOptions=”flagNoExtractUi” //使软键盘不全屏显示,只占用一部分屏幕 同时,
这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键
android:imeOptions=”actionNone” //输入框右侧不带任何提示
android:imeOptions=”actionGo” //右下角按键内容为’开始’
android:imeOptions=”actionSearch” //右下角按键为放大镜图片,搜索
android:imeOptions=”actionSend” //右下角按键内容为’发送’
android:imeOptions=”actionNext” //右下角按键内容为’下一步’ 或者下一项
android:imeOptions=”actionDone” //右下角按键内容为’完成’

注意:如果设置了 键盘没有变化 那么需要单独加一些其他的属性 配合使用,一般添加android:inputType="text"就行了

xml中 属性设置:

1 将singleLine设置为true

2 将inputType设置为text

java代码设置
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH)

二、键盘的监听

1、设置监听 editText.setOnEditorActionListener(this);

2、重写onEditorAction

 @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        doWhichOperation(actionId);
        Log.e("BALLACK", "event: " + event);
        Log.e("BALLACK", "v.getImeActionId(): " + v.getImeActionId());
        Log.e("BALLACK", "v.getImeOptions(): " + v.getImeOptions());
        Log.e("BALLACK", "----------------------------------------------");
        return true;
    }

    private void doWhichOperation(int actionId) {
        switch (actionId) {
            case EditorInfo.IME_ACTION_DONE:
                Log.e("BALLACK", "IME_ACTION_DONE");
                break;
            case EditorInfo.IME_ACTION_GO:
                Log.e("BALLACK", "IME_ACTION_GO");
                break;
            case EditorInfo.IME_ACTION_NEXT:
                Log.e("BALLACK", "IME_ACTION_NEXT");
                break;
            case EditorInfo.IME_ACTION_NONE:
                Log.e("BALLACK", "IME_ACTION_NONE");
                break;
            case EditorInfo.IME_ACTION_PREVIOUS:
                Log.e("BALLACK", "IME_ACTION_PREVIOUS");
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                Log.e("BALLACK", "IME_ACTION_SEARCH");
                break;
            case EditorInfo.IME_ACTION_SEND:
                Log.e("BALLACK", "IME_ACTION_SEND");
                break;
            case EditorInfo.IME_ACTION_UNSPECIFIED:
                Log.e("BALLACK", "IME_ACTION_UNSPECIFIED");
                break;
            default:
                break;
        }

 

本文地址:https://blog.csdn.net/yangjunjin/article/details/107562831

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网