Android – how to hide a snackBar and then display a new one?

I will display the snackBar indefinitely. If Bluetooth is turned off, I want to hide it and display a new Bluetooth to tell users that Bluetooth must be turned on. Before displaying the new snackBar, I turn it off, but only the old snackBar remains visible

activeSnackbar.dismiss();
Snackbar.make(parent, "Bluetooth is off", Snackbar.LENGTH_INDEFINITE)
            .setAction("Turn on", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    BluetoothUtil.enableBluetooth(main);
                }
            }).show()

How do I make a new snackBar disappear before it displays?

resolvent:

You don't need to do anything special for this. Just make the next snackBar and display it. It will make the old snackBar disappear without calling the disass method

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>