在实际开发中有时候会要去判断用户是否在多次的连续点击某个按钮,效果类似于安卓手机中用户连续的点击系统版本会调出开发者模式一样
private void clickStyle()
{
if (time == 0)
{
time = System.currentTimeMillis();
clickCounts = 0;
} else
{
if (System.currentTimeMillis() - time < 500) //计算两次单击的时间差
{
clickCounts++;
if (clickCounts == 2)
{
time = System.currentTimeMillis();
CustomToast.makeTextSucess(getApplicationContext(), "", "在按2次就可以进入设置页面了");
} else if (clickCounts == 3)
{
time = System.currentTimeMillis();
CustomToast.makeTextSucess(getApplicationContext(), "", "在按1次就可以进入设置页面了");
} else if (clickCounts == 4)
{
Intent intent = new Intent(AboutMeActivity.this, AboutMeHideActivity.class);
startActivity(intent);
time = System.currentTimeMillis();
clickCounts = 0;
}
} else
{
time = System.currentTimeMillis();
clickCounts = 0;
}
}
}