我也一直在寻找可以做到这一点的东西。我发现的唯一解决方案是按如下方式扩展EditText:
package com.kylemilligan.test;import android.content.Context;import android.util.AttributeSet;import android.view.inputmethod.EditorInfo;import android.view.inputmethod.InputConnection;import android.widget.EditText;public class NonewlineEditText extends EditText{ public NonewlineEditText(Context context) { super(context); } public NonewlineEditText(Context context, AttributeSet attributeSet) { super(context, attributeSet); } @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { InputConnection connection = super.onCreateInputConnection(outAttrs); int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION; if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) { // clear the existing action outAttrs.imeOptions ^= imeActions; // set the DONE action outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE; } if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) { outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; } return connection; }}
然后在XML中使用类似:
<com.kylemilligan.test.NonewlineEditText android:id="@+id/nonewlineText" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="top|left" android:imeOptions="actionDone" android:minLines="5" />
希望这可以帮助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)