use*_*637 23 android android-edittext
我正在尝试EditText使用软键进行编辑时具有以下特征.我准备了文档,在这里搜索,玩参数但找不到工作配置.
EditView屏幕上的视图有几行高度(例如3-4).我可以实现{1,2,3}和{1,2,4}但不能实现{1,2,3,4}.我的理由是,由于内容是单行(没有换行符),因此不使用Enter键,因此应该能够更改为Done标签.
我的设置代码如下所示
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editText.setHorizontallyScrolling(false);
editText.setSingleLine(false);
// This does not work. Soft keyboard has Enter action.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
Run Code Online (Sandbox Code Playgroud)
可能吗?有什么建议吗?
Joe*_*Joe 35
这种组合(以及EditText方法调用的特定顺序)应该产生您想要的配置:
editText.setInputType(
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
editText.setSingleLine(true);
editText.setLines(4); // desired number of lines
editText.setHorizontallyScrolling(false);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
Run Code Online (Sandbox Code Playgroud)
只需添加
editText.setHorizontallyScrolling(false);
editText.setMaxLines(Integer.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
以编程方式在您的活动中使用您的edittext实例.
它配置EditText实例,以便用户编辑单行字符串,该字符串使用IME选项在多行上进行软包装.
| 归档时间: |
|
| 查看次数: |
7291 次 |
| 最近记录: |