动态禁用 EditText 的自动大写
Dynamically disable auto-capitalization of an EditText
我正在动态创建一个 EditText
并且我想禁用任何句子(新行)的自动大写。
我尝试了 EditText.setInputType(int)
的标志变体,但其中 none 已成功禁用在新行上启用的 shift 键。
这是我的代码:
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: Whosebug to the rescue! What flag do I need?
//
}
editText.setInputType(type);
我在 Whosebug 上广泛搜索了答案,我找到的唯一问题是 this。
正如@CommonsWare 指出的那样,您所做的应该没问题。不可能保证在所有设备上都禁用自动大写。
如果用户使用的是第三方键盘,如 SwiftKey,它可能会覆盖禁用自动大写;用户必须在第三方应用程序设置中手动执行此操作。
我正在动态创建一个 EditText
并且我想禁用任何句子(新行)的自动大写。
我尝试了 EditText.setInputType(int)
的标志变体,但其中 none 已成功禁用在新行上启用的 shift 键。
这是我的代码:
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: Whosebug to the rescue! What flag do I need?
//
}
editText.setInputType(type);
我在 Whosebug 上广泛搜索了答案,我找到的唯一问题是 this。
正如@CommonsWare 指出的那样,您所做的应该没问题。不可能保证在所有设备上都禁用自动大写。
如果用户使用的是第三方键盘,如 SwiftKey,它可能会覆盖禁用自动大写;用户必须在第三方应用程序设置中手动执行此操作。