Multiline EditText with Done SoftInput Action Label on 2.3(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
推荐答案
嗯,重新阅读了 TextView
和 EditorInfo
文档后,已经清楚平台将强制 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:2.3 上带有完成 SoftInput 操作标签的多行 EditText
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01