在特定时间段内禁用Android应用程序上的按钮 [英] Disable button on an Android app for a specific period of time

查看:60
本文介绍了在特定时间段内禁用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应用程序上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆