如何在应用程序外部显示AlertDialog框? [英] How do I make the AlertDialog box appear outside the app?

查看:290
本文介绍了如何在应用程序外部显示AlertDialog框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
public void run() {
    //Create thread that can alter the UI
    AlarmPage.this.runOnUiThread(new Runnable() {
        public void run() {
            cal = Calendar.getInstance();
            //See if current time matches set alarm time
            if((cal.get(Calendar.HOUR_OF_DAY) == alarmTime.getCurrentHour()) 
                    && (cal.get(Calendar.MINUTE) == alarmTime.getCurrentMinute())){
                //If the sound is playing, stop it and rewind
                if(sound.isPlaying()){
                    ShowDialog();
                    alarmTimer.cancel();
                    alarmTask.cancel();
                    alarmTask = new PlaySoundTask();
                    alarmTimer = new Timer();
                    alarmTimer.schedule(alarmTask, sound.getDuration(), sound.getDuration());
                }
                sound.start();
            }       
        }
    });
}

public void ShowDialog() {
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

    alertDialog.setTitle("REMINDER!");
    alertDialog.setMessage("Turn off alarm by pressing off");

    alertDialog.setNegativeButton("Off", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "OFF", Toast.LENGTH_SHORT);
        }
    });

    alertDialog.show();
}

我正在制作一个通知用户的简单闹钟应用程序。我想制作一个警告框,让用户可以选择在闹钟响起时关闭闹钟。我能够制作警报框,但它只出现在不在应用程序之外的应用程序中。我知道应用程序必须在后台运行。如果我需要显示更多代码或更具体,请询问。

I am making a simple alarm clock app that notifies the user. I want to make a alert box that gives the user the option to turn off the alarm when it goes off. I was able to make the alert box, but it only appears in the app not outside of the app. I understand the app has to be in the background running. If I need to show more code or be more specific, just ask please.

推荐答案

添加一行:

public void ShowDialog() {
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

    alertDialog.setTitle("REMINDER!");
    alertDialog.setMessage("Turn off alarm by pressing off");

    alertDialog.setNegativeButton("Off", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "OFF", Toast.LENGTH_SHORT).show();
        }
    });

    alertDialog.show();
    // line you have to add
    alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
}

立即查看。

这篇关于如何在应用程序外部显示AlertDialog框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆