动态禁用 EditText 的自动大写 [英] Dynamically disable auto-capitalization of an EditText

查看:27
本文介绍了动态禁用 EditText 的自动大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态创建一个 EditText 并且我想在任何句子(新行)上禁用自动大写.

I am dynamically creating an EditText and I want to disable auto-capitalization on any sentences (new lines).

我已经尝试了 EditText.setInputType(int) 但他们都没有完成禁用在新行上启用的 shift 键.

I have tried a variation of flags for EditText.setInputType(int) but none of them have accomplished disabling the shift key being enabled on new lines.

这是我的代码:

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
EditText editText = new EditText(context);
int type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE;
if (preferences.getBoolean("disable_suggestions", true)) {
    type |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
}
if (preferences.getBoolean("disable_auto_capitalization", true)) {
    //
    // TODO: StackOverflow to the rescue! What flag do I need? 
    //
}
editText.setInputType(type);

<小时>

我在 StackOverflow 上广泛搜索了答案,我发现的唯一问题是 这个.

推荐答案

正如@CommonsWare 所指出的,你正在做的应该没问题.不可能保证在所有设备上禁用自动大写.

As @CommonsWare pointed out, what you are doing should be OK. It is impossible to guarantee disabled auto-capitalization across all devices.

如果用户使用第三方键盘,如 SwiftKey,它可能会覆盖禁用自动大写;用户必须在第三方应用设置中手动执行此操作.

If the user is using a third-party keyboard, like SwiftKey, it may override disabling auto-capitalization; the user would have to manually do this in the third-party app settings.

这篇关于动态禁用 EditText 的自动大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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