0

I created a shortcut which its intent starts an Activity.
In the activity onCreate I show a android.app.Dialog with custom view.
I want to open the keyboard together with the activity/dialog.
The dialog layout:

 <EditText
    android:id="@+id/reminderEditText"
    android:inputType="text"
    android:maxLength="60"
    android:maxLines="1"
    android:hint="@string/remind_to"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <requestFocus />
</EditText>

The activity declaration in manifest:

    <activity
        android:name=".ReminderActivity"
        android:windowSoftInputMode="stateAlwaysVisible"
        android:label="@string/new_reminder"
        android:exported="true"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

Activity onCreate():

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.dialog_reminder, null);
    EditText editText = view.findViewById(R.id.reminderEditText);
    editText.requestFocus();

    MaterialStyledDialog dialog = new MaterialStyledDialog.Builder(this)
            .setIcon(R.drawable.ic_post_it_2)
            .setCustomView(view, 20, 20, 20, 0)
            .setPositiveText(android.R.string.ok)
            .autoDismiss(true) // close dialog on callbakcs
            .setCancelable(false) // not cancellable on outside touch
            .show();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}

As you can see I've tried every solution I could find online regarding displaying keyboard automatically and yet, no success.

I've also tried the suggested solutions in this question but non of them worked.

SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • Possible duplicate of [AlertDialog with EditText, open soft keyboard automatically with focus on EditText doesn't work](https://stackoverflow.com/questions/12997273/alertdialog-with-edittext-open-soft-keyboard-automatically-with-focus-on-editte) – Mitesh Vanaliya Oct 09 '18 at 13:07
  • @MiteshVanaliya None of the solutions there worked for me – SagiLow Oct 09 '18 at 13:18

2 Answers2

0

please try this:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Mehrdad
  • 1,477
  • 15
  • 17
0

Try this,

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (inputMethodManager != null) {
                    inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
                }
Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29