[英]Replacing Toast with Snackbar sometimes does show for long enough
I'm in the process of replacing several Toast messages with the new Snackbar in the new Android Design Support library. 我正在用新的Android Design支持库中的新Snackbar替换几条Toast消息。
Old code: 旧代码:
Context context = getApplicationContext();
Toast.makeText(context, "Deleted...", Toast.LENGTH_LONG).show();
New code: 新代码:
View view = findViewById(android.R.id.content);
Snackbar.make(view, "Deleted...", Snackbar.LENGTH_LONG).show();
For the most part this is working fine, but I have a couple of toasts that were displayed and then it immediately destroys that activity and launches another activity. 在大多数情况下,此方法运行良好,但是我展示了几个祝酒词,然后立即破坏了该活动并启动了另一个活动。 The snackbar doesn't show up long enough on the screen, as the underlying activity and view are getting destroyed too quickly. 小吃栏在屏幕上显示的时间不够长,因为基础活动和视图被破坏得太快。
Looking for some alternative strategies to make Snackbar work similar to the Toast. 寻找一些替代策略以使Snackbar类似于Toast。
Snackbars are part of your layout. 小吃店是您布局的一部分。 If you are immediately transitioning to another activity, then you should probably stay with Toast messages or either 如果您要立即过渡到另一项活动,那么您可能应该保留Toast消息,或者
I would suggest for creating custom toast which contains ui like snack bar. 我建议创建自定义吐司,其中包含类似小吃店的ui。 For example:- https://stackoverflow.com/a/11288522/1384010 例如: -https : //stackoverflow.com/a/11288522/1384010
You can try this library. 您可以尝试此库。 This is a wrapper for android default snackbar. 这是android默认快餐栏的包装。 https://github.com/ChathuraHettiarachchi/CSnackBar https://github.com/ChathuraHettiarachchi/CSnackBar
Snackbar.with(this,null)
.type(Type.SUCCESS)
.message("Profile updated successfully!")
.duration(Duration.SHORT)
.show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.