|
3 | 3 | import android.app.AlertDialog;
|
4 | 4 | import android.app.Dialog;
|
5 | 5 | import android.content.Context;
|
| 6 | +import android.content.DialogInterface; |
6 | 7 | import android.os.Bundle;
|
| 8 | +import android.os.IBinder; |
7 | 9 | import android.util.Log;
|
8 | 10 | import android.view.View;
|
9 | 11 | import android.view.Window;
|
10 | 12 | import android.view.WindowManager;
|
| 13 | +import android.view.inputmethod.InputMethodManager; |
11 | 14 |
|
12 | 15 | import androidx.annotation.NonNull;
|
13 | 16 | import androidx.annotation.Nullable;
|
@@ -56,12 +59,25 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
56 | 59 | return new AlertDialog.Builder(getActivity())
|
57 | 60 | .setTitle(R.string.change_note_title)
|
58 | 61 | .setView(dialogView)
|
59 |
| - .setCancelable(true) |
60 |
| - .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString())) |
61 |
| - .setNegativeButton(R.string.simple_cancel, null) |
| 62 | + .setCancelable(false) |
| 63 | + .setPositiveButton(R.string.action_edit_save, (dialog, which) -> { |
| 64 | + hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken()); |
| 65 | + listener.onTitleEdited(binding.title.getText().toString()); |
| 66 | + }) |
| 67 | + .setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() { |
| 68 | + @Override |
| 69 | + public void onClick(DialogInterface dialogInterface, int i) { |
| 70 | + hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken()); |
| 71 | + } |
| 72 | + }) |
62 | 73 | .create();
|
63 | 74 | }
|
64 | 75 |
|
| 76 | + private void hideKeyboard(IBinder windowToken) { |
| 77 | + InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
| 78 | + inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS); |
| 79 | + } |
| 80 | + |
65 | 81 | @Override
|
66 | 82 | public void onActivityCreated(Bundle savedInstanceState) {
|
67 | 83 | super.onActivityCreated(savedInstanceState);
|
|
0 commit comments