android toast点击事件_android生命周期七种方法
大家好,又见面了,我是你们的朋友全栈君。
设置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
相关文章
- android系统开机画面_Android开机画面
- android开机动画多长时间_Android开机动画原理分析
- 基于chromium for android开发Android浏览器
- android 常用加密,分享一下Android各种类型的加密
- android图片资源加密,Android平台图像文件加密
- android okio使用方法,Android 开源框架 Okio 原理剖析「建议收藏」
- android deeplink流程,Android Deeplink探究[通俗易懂]
- Android angle_android 界面悬停
- Android n_android 反编译
- Android Looper,Handler,Message,MessageQueue介绍
- Android resource linking failed_android sdk location should not
- 【Android NDK 开发】JNI 方法解析 ( JNIEXPORT 与 JNICALL 宏定义作用 )
- 【Android 安全】DEX 加密 ( Java 工具开发 | apk 文件对齐 )
- 【Android Gradle 插件】build.gradle 中的 android 配置 ( 配置项 | compileSdkVersion 配置 | buildToolsVersion 配置 )
- 【错误记录】Android 应用安装后出现两个启动图标 ( 排查应用及依赖库中配置了 android.intent.category.LAUNCHER 的 Activity )
- 【Android UI】贝塞尔曲线 ④ ( 使用 android.graphics.Path 提供的 cubicTo 方法绘制三阶贝塞尔曲线示例 )
- 【Android Gradle 插件】Gradle 扩展属性 ④ ( 扩展属性访问方式 | 直接访问扩展属性 | 通过 ext 对象访问 | 在 gradle.properties 中定义扩展属性 )
- android开发,http工具类详解编程语言
- Android 9.0 概览
- android键盘事件和屏幕事件的运行原理及交互实现
- android自定义Android菜单背景的代码
- 浅析Android模拟键盘鼠标事件
- android计算器代码示例分享