多行的EditText与2.3 Done(完成)SoftInput行动标签 [英] Multiline EditText with Done SoftInput Action Label on 2.3
问题描述
有没有办法有一个多行的EditText
present并使用输入法动作标签完成在Android 2.3?
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动作标签完成(安卓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
这就是:
- 类=
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMAL
- 标记=
InputType.TYPE_TEXT_FLAG_MULTI_LINE
- class =
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMAL
- flags =
InputType.TYPE_TEXT_FLAG_MULTI_LINE
推荐答案
好了,经过重新阅读的TextView
和 EditorInfo
的文档,它已经很清楚,该平台将迫使<一个href="http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_FLAG_NO_ENTER_ACTION"><$c$c>IME_FLAG_NO_ENTER_ACTION$c$c>多行文本的意见。
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
键,让平台上配置它们后调整输入法的选项:
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.
这篇关于多行的EditText与2.3 Done(完成)SoftInput行动标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!