我已经设置了在3秒后打开拨号器的意图,但我想使用进度条在屏幕上显示意图的进度(如左图所示)。帮助,任何人?
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"));
startActivity(intent);
}
}, 3000); // 5 minutes delay before execute run()
答案 0 :(得分:0)
这个怎么样?按顺序发布一些Runnables,最后一个实际执行代码。
final Handler handler = new Handler();
final ProgressBar bar = ...; // create and add a new progress bar and set max 3000
handler.postDelayed(new Runnable()
{
int elapsed = 0;
final int STEP_MS = 500;
@Override
public void run()
{
elapsed += 500;
if (elapsed >= 3000)
{
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"));
startActivity(intent);
}
else
{
bar.setProgress(elapsed);
handler.postDelayed(this, 500);
}
}
}, 500);