2.3 上带有完成 SoftInput 操作标签的多行 EditText [英] Multiline EditText with Done SoftInput Action Label on 2.3

查看:12
本文介绍了2.3 上带有完成 SoftInput 操作标签的多行 EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Android 2.3 上显示多行 EditText 并使用 IME 操作标签完成"?

Is there a way to have a Multi-Line EditText present and use the IME Action Label "Done" on Android 2.3?

在 Android 2.2 中这不是问题,输入按钮显示 IME 操作标签完成"(android:imeActionLabel="actionDone"),并在单击时关闭软输入.

In Android 2.2 this is not a problem, the enter button shows the IME Action Label "Done" (android:imeActionLabel="actionDone"), and dismisses Soft Input when clicked.

在为多行配置 EditText 时,Android 2.3 移除了为软输入键盘显示完成"操作的功能.

When configuring an EditText for multi-line, Android 2.3 removes the ability to show the "Done" action for the Soft Input keyboard.

我已经设法通过使用 KeyListener 来改变软输入回车按钮的行为,但是回车按钮看起来仍然像回车键.

I have managed to alter the behaviour of the Soft Input enter button by using a KeyListener, however the enter button still looks like an enter key.

这里是EditText

<EditText
        android:id="@+id/Comment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="0dp"
        android:lines="3"
        android:maxLines="3"
        android:minLines="3"
        android:maxLength="60"
        android:scrollHorizontally="false"
        android:hint="hint"
        android:gravity="top|left"
        android:textColor="#888"
        android:textSize="14dp"
        />
<!-- android:inputType="text" will kill the multiline on 2.3! -->
<!-- android:imeOptions="actionDone" switches to a "t9" like soft input -->

当我在活动中加载设置内容视图后检查 inputType 值时,它显示为:

When I check the inputType value after loading setting the content view in the activity, it shows up as:

inputType = 0x20001

这是:

  • class = TYPE_CLASS_TEXT |TYPE_TEXT_VARIATION_NORMAL
  • 标志 = InputType.TYPE_TEXT_FLAG_MULTI_LINE

推荐答案

嗯,重新阅读了 TextViewEditorInfo 文档后,已经清楚平台将强制 IME_FLAG_NO_ENTER_ACTION 进行多行文本视图.

Well, after re-reading the TextView and EditorInfo docs, it has become clear that the platform is going to force IME_FLAG_NO_ENTER_ACTION for multi-line text views.

请注意,TextView 会自动在多行上为您设置此标志文本视图.

Note that TextView will automatically set this flag for you on multi-line text views.

我的解决方案是继承 EditText 并在让平台配置它们后调整 IME 选项:

My solution is to subclass EditText and adjust the IME options after letting the platform configure them:

@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;
}

在上面,我也强制 IME_ACTION_DONE,即使这可以通过繁琐的布局配置来实现.

In the above, I'm forcing IME_ACTION_DONE too, even though that can be achieved through tedious layout configuration.

这篇关于2.3 上带有完成 SoftInput 操作标签的多行 EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆