0
0

More than 3 years have passed since last update.

Xamarin.Android AlertDialog中のハードウェアキーボードを検知する方法

Posted at

ハードウェアキーボードとは端末自体にキーボードが存在するものを考えています。
onKeyDown:をなぜ使わないかというとDialog表示中は、
キーイベントが検知できないので別の方法で用意してあげる必要があります。

その為の回避策はこちらです。

                        AlertDialog dialog = new AlertDialog.Builder(this)
                            .SetTitle("")
                            .SetMessage("ログインに失敗しました。")
                            .SetPositiveButton("OK", (sender, e) => {
                                Finish();
                            })
                            // キャンセル表示をする場合はコメント解除してください。
                            //.SetNegativeButton("Cancel", (sender, e) => { })
                            .Show(); // Important, or GetButton() will return null


                        dialog.KeyPress += (sender, e) => {
                            if (e.KeyCode == Keycode.Enter)
                            {
                                dialog.Dismiss();
                            }
                        };

if(e.KeyCode ==でブレイクポイントを設定して、
ビルドして実際にハンドリングを行いたいボタンを押せば、
どうやってif文内に入力すればいいかわかります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0