gpt4 book ai didi

android - 如何自动大写 AlertDalog 中的 EditText?

转载 作者:搜寻专家 更新时间:2023-11-01 07:59:15 24 4
gpt4 key购买 nike

我想显示一个包含自动大写单词的 EditText 的 AlertDialog。

正在关注 this questionthat one ,我设法让 AlertDialog 在显示对话框时自动显示键盘,并在用户单击 EditText 时将第一个字母大写。但在用户点击之前,键盘会以小写模式显示。

如何让键盘在大写(自动大写单词)模式下自动打开?

我的相关代码如下:

    input = new EditText(context);
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);

dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

还尝试在对话框的 onShowListenerrequestFocus() 但没有帮助。

最佳答案

您只需在 AlertDialog 声明后使用以下代码即可。

AlertDialog.Builder alert = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);

final EditText edittext = new EditText(getApplicationContext());
// Just use it here, there is much more options in the link below
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

Look for other options here

关于android - 如何自动大写 AlertDalog 中的 EditText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com