2

I want to show an AlertDialog containing an EditText that auomtically capitalizes words.

Following this question and that one, I managed to get the AlertDialog show the keyboard automatically when the dialog is shown, and also capitalize the first letter when the user clicks on the EditText. But until the user clicks, the keyboard shows in lowercase mode.

How can I make the keyboard open automatically in upper-case (auto-capitalize words) mode?

My relevant code is as follows:

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

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

Also tried to requestFocus() in the dialog's onShowListener but it didn't help.

Community
  • 1
  • 1
Michael Litvin
  • 3,444
  • 1
  • 27
  • 35

2 Answers2

4

You just need to use the following code after your AlertDialog declaration.

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

Will
  • 749
  • 2
  • 7
  • 17
0

A workaround that worked for me was to avoid using setMessage(), and adding the message into my own view instead (using setView()).

Michael Litvin
  • 3,444
  • 1
  • 27
  • 35