美文网首页
EditText 同时支持 imeOptions 和 多行

EditText 同时支持 imeOptions 和 多行

作者: 熊er | 来源:发表于2017-04-05 12:50 被阅读0次

方法一

代码中设置

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

相关文章

网友评论

      本文标题:EditText 同时支持 imeOptions 和 多行

      本文链接:https://www.haomeiwen.com/subject/vfqpottx.html