【问题标题】:How to auto-capitalize an EditText inside an AlertDalog?如何在 AlertDalog 中自动大写 EditText?
【发布时间】:2014-05-11 20:58:19
【问题描述】:

我想显示一个包含自动大写单词的 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(),但没有帮助。

【问题讨论】:

    标签: android


    【解决方案1】:

    您只需要在您的 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

    【讨论】:

      【解决方案2】:

      对我有用的解决方法是避免使用setMessage(),而是将消息添加到我自己的视图中(使用setView())。

      【讨论】:

        猜你喜欢
        • 2011-10-22
        • 1970-01-01
        • 1970-01-01
        • 2013-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-22
        • 2020-02-07
        相关资源
        最近更新 更多