EditText 同时支持 imeOptions 和 多行

方法一

代码中设置

editText.setHorizontallyScrolling(false);
editText.setMaxLines(Integer.MAX_VALUE);

方法二

重写 EditText 的 onCreateInputConnection( ) 方法

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
    if ((imeActions & EditorInfo.IME_ACTION_SEND) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEND;
    }
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    return connection;
}

参考资料:
Multiline EditText with Done SoftInput Action Label on 2.3

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,642评论 2 45
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,593评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,268评论 19 139
  • 外甥女婚礼上的感动: 1 婚礼前夕,娘家人们听到外甥女与男方亲戚的交流,大家都惊叹她的本地话竟学得如此的熟练。让对...
    雨丝飘飘阅读 357评论 0 0
  • 威武5连 一排二班 23-小晴 转眼间,在行动营的日子就这样结束了。这22天有收获也有遗憾。 一、加入行动营 当初...
    常小晴阅读 203评论 1 2