zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

android toast点击事件_android生命周期七种方法

Android事件方法 点击 生命周期 Toast 七种
2023-06-13 09:13:40 时间

大家好,又见面了,我是你们的朋友全栈君。

设置Android Toast持续时间非常长(例如1分钟)(Set Android Toast duration to be really long (e.g., 1 minute))

我尝试将我的Toast节目时间设置为1分钟。 我试试这个:

final Toast toast = Toast.makeText(getApplicationContext(), “MESSAGE”, Toast.LENGTH_LONG );

toast.show();

Handler handler = new Handler();

handler.postDelayed(new Runnable() {

@Override

public void run() {

toast.cancel();

}

}, 60000);

谢谢你的帮助。

I try to set my Toast show duration like 1minute. I try this:

final Toast toast = Toast.makeText(getApplicationContext(), “MESSAGE”, Toast.LENGTH_LONG );

toast.show();

Handler handler = new Handler();

handler.postDelayed(new Runnable() {

@Override

public void run() {

toast.cancel();

}

}, 60000);

Thanks for your help.

原文:https://stackoverflow.com/questions/21134640

更新时间:2020-01-13 14:51

最满意答案

由于LENGTH_SHORT为2秒(而LENGTH_LONG为3.5秒),请尝试以下操作:

for (int i=0; i < 30; i++)

{

Toast.makeText(this, “MESSAGE”, Toast.LENGTH_SHORT).show();

}

Since LENGTH_SHORT is 2 seconds (and LENGTH_LONG is 3.5 seconds), try this:

for (int i=0; i < 30; i++)

{

Toast.makeText(this, “MESSAGE”, Toast.LENGTH_SHORT).show();

}

2014-01-15

相关问答

LENGTH_SHORT和LENGTH_LONG的值为0和1.这意味着它们被视为标志而不是实际持续时间,因此我认为不可能将持续时间设置为除这些值之外的任何值。 如果要向用户显示更长的消息,请考虑状态栏通知 。 状态栏通知可以在不再相关的情况下以编程方式取消。 The values of LENGTH_SHORT and LENGTH_LONG are 0 and 1. This means they are treated as flags rather than actual durations

尝试这个 : btnToast.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Toast msg = Toast.makeText(MainActivity.this, text, duration );

msg.show();

I got it to work by removing the context and duration variabl

在这里回答 像你提到的Toast.LENGTH_SHORT和Toast.LENGTH_LONG不在ms,而是0或1。 实际持续时间为: private static final int LONG_DELAY = 3500; // 3.5 seconds

private static final int SHORT_DELAY = 2000; // 2 seconds

Answered here. Like you mentioned Toast.LENGTH_SHORT and Toast.LE

由于您的课程/活动中未定义上下文,因此您使用的更好 public void onStopTrackingTouch(SeekBar seekBar) {

Toast.makeText(this, “Now stopped”, Toast.LENGTH_LONG).show();

} // if this method is inside activity

要么 public void onStopTrackingTouch(SeekBar seekBar) {

Toas

如果已经显示,调用cancel()方法来隐藏Toast。 看看这个API。 这可以简单地称为吐司的对象。 Toast toast = new Toast(context);

toast.setText(“Text”);

toast.show();//(call show() to display Toast)

toast.cancel();//(call cancel() to hide Toast).

call cancel() method to hide Toast if alrea

是否可以制作具有自定义持续时间(8或26秒)的Toast? 不,这正是您链接的两个问题的答案。 我已经阅读了问题设置Toast出现长度并且Android Toast可以比“Toast.LENGTH_LONG”长吗? 但这些问题都没有得到回答。 那是因为(因为两个链接指出)这是不可能的,所以没有“工作答案”。 答案确实建议您考虑的替代方案。 Is it possible to make a Toast with custom duration (8 or 26 seconds)? No, which

由于LENGTH_SHORT为2秒(而LENGTH_LONG为3.5秒),请尝试以下操作: for (int i=0; i < 30; i++)

{

Toast.makeText(this, “MESSAGE”, Toast.LENGTH_SHORT).show();

}

Since LENGTH_SHORT is 2 seconds (and LENGTH_LONG is 3.5 seconds), try this: for (int i=0; i < 30; i++)

{

当你写这行时,你正在实例化一个新的Toast对象 Toast toastObject = Toast.makeText(this, “”, Toast.LENGTH_LONG); 然后当你打电话 toastObject.cancel(); 你正在取消你刚刚创建的Toast ,它是空的。 Toast toastObject = Toast.makeText(this, “”, Toast.LENGTH_LONG);

保留Toast的参考,然后可以使用cancel()方法, 这里的文档。 为了知道何时需要取消吐司,您需要使用活动的OnTouchEvent拦截触摸事件并获取触摸事件的位置x / y。 然后你可以将它与myToast.getView().getY()和getX()进行比较,得到左上角和getWidth()以及getHeight() 。 Keep a reference of you Toast, you can then use the cancel() method, documentation

编辑:完整的工作代码 MainActivity.java : public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

// Declare the messages to show

private String text1 = “radio button 1”;

private String text2 = “radio butt

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/194517.html原文链接:https://javaforall.cn