简体   繁体   English

显示“吐司”对话框是否打开?

[英]Show toast WHILE dialog is open?

This is an extremely simple issue I am facing. 这是我面临的一个非常简单的问题。 Basically, I am requesting run-time permissions—but I also want to show a toast at the same time as the permission request: 基本上,我是在请求运行时权限,但我也想在权限请求的同时显示祝酒词:

Relevent Code: 相对编号:

if ((ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED
                                    || ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
                                ActivityCompat.requestPermissions(MainActivity.this, new String[]{


                                        Manifest.permission.RECORD_AUDIO,
                                        Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);

                                Toast.makeText(MainActivity.this, "You must enable BOTH", Toast.LENGTH_LONG).show();

The problem is, the toast quickly disappears (within maybe less than 0.5 second), as soon as the permission dialog appears. 问题是,只要出现权限对话框,吐司便会很快消失(可能不到0.5秒)。

在此处输入图片说明

Is this a bug on Android? 这是Android上的错误吗? Or is there some work around that I'm missing? 还是有一些我所缺少的工作?

Toasts don't display permanently. 吐司面包不会永久展示。 The entire concept of a Toast is that it pops up then fades away. Toast的整个概念是它会弹出然后消失。 If you want something more permanent, you'll have to implement it yourself. 如果您想要更永久的东西,则必须自己实施。

这是android中权限的默认对话框,因此this.ya没有解决方案,但是如果您创建自定义对话框,则可以在所需位置显示它。

Toast message is displayed for short duration of 2 sec or for long duration of 3.5 sec and it cannot be changed. 显示Toast消息的持续时间为2秒钟较短或3.5秒钟较长,并且无法更改。

If you wish to display the toast message for longer time then you need to display it continuously. 如果您希望将烤面包消息显示更长的时间,则需要连续显示它。

for (int i=0; i < 5; i++){
    Toast.makeText(this, "Your toast message", Toast.LENGTH_SHORT).show();
}

It will display your toast for 10 seconds. 它将显示您的吐司10秒钟。

Hope it helps :) 希望能帮助到你 :)

尝试使上下文为

Toast.makeText(getApplicationContext(),"YOUR TEXT",Toast.LENGTH_LONG).show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM