Disable button on an Android app for a specific period of time(在特定时间段内禁用 Android 应用程序上的按钮)
问题描述
我正在 android studio 中构建一个登录风格的应用程序.作为其中的一部分,我创建了一个规则,如果监视无效登录尝试次数的计数器变为 0.我目前知道当计数器变为 0 时,登录按钮被禁用.我想知道是否有任何方法可以在一段时间内禁用此按钮,而不是无限期?
I'm building a login style application within android studio. As part of this I have created a rule that if the counter which monitors the number of invalid login attempts, gets to 0. I've currently got it that when the counter gets to 0, the login button is disabled. I was wondering if there is any way of disabling this button for a set period of time, rather than for infinity?
switch (counter) {
case 0:
b1.setEnabled(false);
break;
case 1:
tx1.setBackgroundColor(Color.RED);
break;
case 2:
tx1.setBackgroundColor(Color.YELLOW);
break;
}
推荐答案
使用以下代码.当您放入 OnCreate() 方法时,当活动或片段开始时,它将在 5 秒后禁用按钮.
Use following code. it will disabled button after 5 seconds when activity or fragment start when you put in OnCreate() method.
new Handler().postDelayed(new Runnable()
{
public void run()
{
b1.setEnabled(false);
}
}, 5000 //Specific time in milliseconds
);
这篇关于在特定时间段内禁用 Android 应用程序上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在特定时间段内禁用 Android 应用程序上的按钮


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01