禁用 POSITIVE_BUTTON(“继续”)5 秒
我的应用程序启动时会显示一个警报弹出窗口。我希望用户通读它,所以我想将“继续”按钮灰显 5 秒,然后启用它以便用户可以继续。
if (alertDialog == null) {
alertDialog = new AlertDialog.Builder(this).setPositiveButton("Continue",
new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//continue with the app
}
}).create();
alertDialog.setTitle("My Title");
alertDialog.setView(myView);
}
if ((!alertDialog.isShowing())) {
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
将按钮设置为 false 后,我无法将其设置回 true。我尝试使用 Thread.sleep(5000l) 并创建自己的对话框。他们都没有工作。我怎样才能实现我的目标?
谢谢, 阿卡什
I have a alert pop-up which i show when my app launches. I want the user to read through it, so i want to grey out the continue button for 5 secs, then enable it so the user can continue.
if (alertDialog == null) {
alertDialog = new AlertDialog.Builder(this).setPositiveButton("Continue",
new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//continue with the app
}
}).create();
alertDialog.setTitle("My Title");
alertDialog.setView(myView);
}
if ((!alertDialog.isShowing())) {
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
After setting the button to false, i'm unable to set it back to true. I tried using Thread.sleep(5000l) and creating my own dialog. Niether of them worked. How can i go about achieving my objective?
Thanks,
AkasH
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户代码回调完成后,UI 元素全部渲染完毕。这就是为什么仅仅添加延迟没有帮助。
您可能想要启动一个线程或一个
AsyncTask
,其中doInBackground
方法正在倒计时(可能在循环中,因此您可以在 ok 字段中显示一个计数器),然后在onPostExecute
中启用按钮伪代码:
The UI elements are all rendered in one go after the callback from the user code has finished. This is why just adding a delay does not help.
You may want to start a thread or an
AsyncTask
where thedoInBackground
method is counting down (probably in a loop, so you can show a counter in the ok field) and then inonPostExecute
enable the buttonPseudo-code: