简体   繁体   English

Toast 不显示在屏幕上

[英]Toast does not show on screen

I am sorry if it is a too simple question.如果这是一个太简单的问题,我很抱歉。 I have searched everywhere, but could not find a solution.我到处搜索,但找不到解决方案。 For about 3 days Toast does not show up on my app.大约 3 天 Toast 没有出现在我的应用程序上。 I tried to do a lot of things.我试着做很多事情。

  • Change makeText(this) to makeText(getApplicationContext()) or makeText(getBaseContext()) makeText(this)更改为makeText(getApplicationContext())makeText(getBaseContext())

  • Change position of the Toast and tried other solution on StackOverflow, but it did not appear.更改 Toast 的 position 并在 StackOverflow 上尝试了其他解决方案,但没有出现。

Here is the code这是代码

Toast.makeText(this, "Great", Toast.LENGTH_SHORT).show();

Try this.尝试这个。 Toast.makeText(getApplicationContext(), "Test string", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "测试字符串", Toast.LENGTH_SHORT).show();

The most important one, make sure your Android Notifications are on for your app, else the Toast will not be shown.最重要的是,确保您的应用程序的 Android 通知已打开,否则将不会显示 Toast。

Try this:尝试这个:

Toast.makeText(yourActivity.this, "Try Toast", Toast.LENGTH_SHORT).show();

And make sure you use the codes in the correct line.并确保您在正确的行中使用代码。

Here is an example这是一个例子

Toast.makeText(getActivity(), "This is my Toast message,". Toast.LENGTH_LONG);show(); Toast.makeText(getActivity(), "这是我的 Toast 消息,". Toast.LENGTH_LONG);show();

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

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