ref*_*log 23
它在SDK中的ApiDemos中全面解释.您想要的示例名为:ProgressBar3.java,可以在\ ApiDemos\src\com\example\android\apis\view \中找到
此外,如果要删除对话框的边框以便只显示进度条,则可以将对话框本身定义为透明视图/叠加层(在示例中也会对此进行说明).
小智 22
如果您不需要对话框,只需将progressBar放在布局中,就像任何其他视图项一样,并将可见性设置为'INVISIBLE',甚至默认为'GONE'.
然后只需在代码中使用setVisibility将其更改为"VISIBLE"时显示它,并在任务完成时通过再次将其设置为"INVISIBLE"或"GONE"来重新隐藏它.
例如
MyTask {
// get handle on ProgressBar ViewItem defined in XML (id:progressBar)
ProgressBar progressBar = findViewById(R.id.progressBar);
//starting task, show progress bar
progressBar.setVisibility(View.VISIBLE);
// Do some stuff...
//task done, hide it again
progressBar.setVisibility(View.GONE);
}
Run Code Online (Sandbox Code Playgroud)
这是一个简单的版本,都在UI线程中完成,但如果您使用异步任务或线程处理程序,这应该很容易适应.当您在UI线程中时,只需显示,隐藏和发布对话框的任何更新,并在后台执行长时间运行的任务.
| 归档时间: |
|
| 查看次数: |
64422 次 |
| 最近记录: |