android – 如何使用EditText,IME Action,textMultiLine来为JellyBean工作

我遇到了相当难题,但未找到解决方案.显然,JellyBean会改变IME操作的处理方式.我发现很多网站提供的解决方案确实有效,但仅适用于单行内容的EditTexts.示例: Stackoverflow: onEditorAction

我的EditText小部件完美无缺,直到JellyBean.在用户点击“完成”(返回)键之前,它将正确地自动换行.然后它用OnEditorActionListener捕获事件并相应地处理.我已尝试使用以下XML属性更改设置的多种变体无效:

> singleLined
> scrollHorizo​​ntally
> inputType
> imeOptions
>线条

我只能在没有onEditorAction事件的情况下进行自动换行,或者在onEditorAction事件触发时没有自动换行.如何为JellyBean提供自动换行和处理软键盘输入键?

更新1:包括请求的代码.请注意,现在它是如何适用于除JellyBean之外的所有平台.正如我之前所说,尝试多种不同的XML设置无济于事.

更新2:管理以获取运行JellyBean 4.1.1的Asus Transformer.工作良好.那么这可能是设备特定的错误?我的另一个JellyBean设备是运行4.1.2的Nexus 7.有人可以用其他设备验证吗?

码:

private class OnMyEditorActionListener implements OnEditorActionListener {
    public boolean onEditorAction(TextView v,int actionId,KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_GO) {
            doSomething();
            return true;
        }
        return false;
    }
}
<EditText
    android:id="@+id/editBox_Box_et"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|center_horizontal"
    android:imeOptions="actionGo"
    android:inputType="textMultiLine|textNoSuggestions"
    android:padding="@dimen/spacing_half"
    android:textSize="24sp" >
</EditText>

解决方法

自己提交ID到提交/转到按钮

在活动中:

private class OnMyEditorActionListener implements OnEditorActionListener {
    public boolean onEditorAction(TextView v,KeyEvent event) {
        if (actionId == R.id.your_new_ID || actionId == EditorInfo.IME_Null) {
            doSomething();
            return true;
        }
        return false;
    }
}

在xml中:

<EditText
    android:id="@+id/editBox_Box_et"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|center_horizontal"
    android:inputType="textMultiLine|textNoSuggestions"
    android:padding="@dimen/spacing_half"
    android:textSize="24sp" 
    android:imeActionId="@+id/your_new_ID"
    android:imeActionLabel="Go"> </EditText>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...