0

My current progress dialog freezes the UI, I mean, I can't use the app while the dialog is showing, I cannot move, or click any button. Is it possible to show a dialog without it takes any focus?(So I could click buttons in the current activity).

idish
  • 3,190
  • 12
  • 53
  • 85
  • Without seeing any of your code, I'm guessing here. Is your dialog modal perhaps? – Ben van Gompel Nov 02 '12 at 22:49
  • @BenvanGompel I'm just using a ProgressDialog dialog – idish Nov 02 '12 at 22:51
  • Does the ProgressDialog block the main thread or does the action that created the Dialog (like database access or downloading) do this? – Sam Nov 02 '12 at 22:55
  • @Sam While the progressdialog is shown, there's an asynctask downloading some data off the internet. so the ProgressDialog blocks the main thread. – idish Nov 02 '12 at 22:58

1 Answers1

1

ProgressDialog, like any dialog, always steals focus from your current activity. If you want to embed a progress bar into your current layout, use a ProgressBar, using setVisible(true) when you start your long running operation and setProgress to update the progress bar (or use indeterminate mode if you don't know how long the task will take).

Styling the Progress Bar is primarily done via their style, selecting one of the built in types of Progress Bar:

  • The default style (i.e., no style specified): Spinning wheel
  • Widget.ProgressBar.Horizontal - Horizontal Bar
  • Widget.ProgressBar.Small - Smaller spinning wheel
  • Widget.ProgressBar.Large - Larger spinning wheel
  • Widget.ProgressBar.Inverse - Spinning wheel on light background
  • Widget.ProgressBar.Small.Inverse - Smaller spinning wheel on light background
  • Widget.ProgressBar.Large.Inverse - Larger spinning wheel on light background

You'd apply these by adding the style attribute to your ProgressBar xml:

 <ProgressBar
     style="@android:style/Widget.ProgressBar.Horizontal"
     ... />

If it is custom coloring you require, you can use the solution posted here, which utilizes setColorFilter.

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • It seems to be the answer, but I can't turn my progressbar to the other mode(not showing how long the task will take).. and I've searched over the internet, can you please provide a code sample please? – idish Nov 02 '12 at 23:29
  • Oh wait, now I see my progressbar, it looks ok but how can I design it? it doesn't have any backgroundcolor or something. – idish Nov 02 '12 at 23:31
  • @idish - check out my edited answer - between the `style`s available to ProgressBar and custom coloring, that should get you close to what you need. Otherwise, please feel free to edit your question with some more detail on what you are looking for. – ianhanniballake Nov 03 '12 at 05:06
  • It looks pretty difficult to style the progressbar as I want.. It doesn't look like a progress bar, it's looks very neat. There's no way of showing a progressbar that looks like the progressdialog? – idish Nov 03 '12 at 09:12
  • @idish - 'like the progressdialog' isn't quite enough information. Both ProgressDialog and ProgressBar share the same type of Spinner or Horizontal styles and determinate and indeterminate modes. – ianhanniballake Nov 03 '12 at 15:10
  • sorry for misunderstanding, i meant that the progressbar will look like default progressdialog with the spinner, pos sible to do so? – idish Nov 03 '12 at 18:57
  • something like that huuah.com/images/androiddialog/progress.png – idish Nov 03 '12 at 18:59