Android - show an indeterminate progressbar without the dialog

后端 未结 5 1880
既然无缘
既然无缘 2020-12-03 03:17

I want to show my progressbar in the center of the screen when a processing happens on a button click. But I just want the progressbar without the dialog box..

Is th

相关标签:
5条回答
  • 2020-12-03 03:40

    If you need no dialog, just put the progressBar in your layout like any other view item, and set the visibility to 'INVISIBLE' or even 'GONE' by default.

    Then just show it whenever you need to by changing it to 'VISIBLE' using setVisibility in your code, and re-hide it when the task is done by making it 'INVISIBLE' or 'GONE' again.

    e.g.

    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);
    
    }
    

    This is a simple version, all done in the UI thread, but this should be easy to adapt if you are using an asynchronous task or thread handlers. Just show, hide, and post any updates to the dialog while you are in the UI thread, and do your long-running task in the background.

    0 讨论(0)
  • 2020-12-03 03:42

    The answer by @Jesse Finnerty solved my issue. what i did was:

    private ProgressBar mprogressBar;
    

    The inside oncreate() just like other buttons and textviews i did, mprogressBar = (ProgressBar) findViewById(R.id.progressBar);

    Then at the point i want spinning wheel to appear i give command

    mprogressBar.setVisibility(View.VISIBLE);
    

    at the point where i want it to disappear .

    mprogressBar.setVisibility(View.INVISIBLE);
    

    This is under switch actually. so that as the states in my program change, the progress bar appears and disappears

    0 讨论(0)
  • @reflog: That's not what is needed I guess.

    @lostInTransit:

    The correct way to achieve this is as follows:

    1. Create ur own dialog
    2. Put progress bar as only view on the dialog
    3. Set dialog window background transparent
    4. Show the dialog.

    That's it. It works for me on devices with 1.5 to 2.1. Not tried on 2.2.

    -Yogesh

    0 讨论(0)
  • 2020-12-03 04:02

    There is a great example to do what Yogesh is suggesting at:

    How to center progress indicator in ProgressDialog easily (when no title/text passed along)

    Credit goes to Macarse for posting it.

    0 讨论(0)
  • 2020-12-03 04:04

    It's explained in full in ApiDemos inside the SDK. The example that you want is named: ProgressBar3.java and can be found in \ApiDemos\src\com\example\android\apis\view\

    Also, if you want to remove the borders of the dialog so that only the progress bar appears you can define the dialog itself as a transparent view/overlay (it's explained in the examples as well).

    0 讨论(0)
提交回复
热议问题