次のコードを使用して、アクティビティに [OK] ボタンのある AlertDialog があります。
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
//Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Welcome to AndroidHive.info");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.icon);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
}
});
alertDialog.show();
これはアプリケーション内では問題なく動作しますが、アプリケーションの外にいてもこれを実行して表示したいと考えています。もちろん、アプリケーションはまだ実行されており、閉じられていません。トーストによく似ています。OKボタン付きのToastが使えても嬉しいです。
どんな助けでも大歓迎です。ありがとう。