EditText 同时支持 imeOptions 和 多行

2017-04-05  本文已影响0人  熊er

方法一

代码中设置

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

上一篇 下一篇

猜你喜欢

热点阅读