I have a class AsyncTask which does the download, and by itself while the download is in progress, the spinning ProgressBar should be displayed.

The implementation of the ProgressBar itself is understandable, but how to make it so that the activation in which the download starts is darkened a little and the ProgressBar starts spinning in the center, at the end of the download it all disappears and only the activation over which the ProgressBar was called is left ...

I thought to do so, in AsyncTask in the onPreExecute() method, send an intent to open another activation, which will be translucent and set the ProgressBar in it, when AsyncTask work, then in the onPostExecute() method, close the activation ...

But I think this is a crooked idea ... Tell me how it is done correctly?

    3 answers 3

    Use for such purposes ProgressDialog

    Add style:

     <style name="MyTheme" parent="android:Theme.Holo.Dialog"> <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item> <item name="android:windowBackground">@color/transparent</item> <item name="android:textColorPrimary">#FFFFFF</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:textColor">#FFFFFF</item> <item name="android:textStyle">normal</item> <item name="android:textSize">12sp</item> </style> 

    and

     <style name="CustomAlertDialogStyle"> <item name="android:bottomBright">@color/transparent</item> <item name="android:bottomDark">@color/transparent</item> <item name="android:bottomMedium">@color/transparent</item> <item name="android:centerBright">@color/transparent</item> <item name="android:centerDark">@color/transparent</item> <item name="android:centerMedium">@color/transparent</item> <item name="android:fullBright">@color/transparent</item> <item name="android:fullDark">@color/transparent</item> <item name="android:topBright">@color/transparent</item> <item name="android:topDark">@color/transparent</item> </style> 

    Colour:

     <color name="transparent">#00000000</color> 

    and cause a dialogue

      progressDialog = new ProgressDialog(getActivity(),R.style.MyTheme); progressDialog.setCancelable(false); progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small); progressDialog.show(); 
    • Yes, but I do not really need it. I am interested in this situation, imagine the device’s screen with content (I twist and so on), and when the user clicks on “Load”, the screen is covered by a semi-transparent gray photo and in the center of which is a dialogue ... The question is how to close The screen is a translucent photo and put in the center of the dialogue. - Aleksey Timoshchenko
    • @AlekseyTimoshchenko, updated the answer - VAndrJ

    Announce in your activity

     private ProgressDialog progressDialog = null; 

    When you need to show a dialogue with a spinning spinner, call this method:

     private void showProgress(String text) { if (progressDialog == null) { try { progressDialog = ProgressDialog.show(this, "", text); progressDialog.setCancelable(false); } catch (Exception e) { } } } 

    When to hide this

     public void hideProgress() { if (progressDialog != null) { progressDialog.dismiss(); progressDialog = null; } } 
    • I think you didn’t fully understand my question ... Following your answer, you just show how to turn on and knock out a dialogue, I know that. I am interested in this situation, imagine the device’s screen with content (I twist and so on), and when the user clicks on “Load”, the screen is covered by a semi-transparent gray photo and in the center of which is a dialogue ... The question is how to close The screen is a translucent photo and put in the center of the dialogue. - Aleksey Timoshchenko
    • If you tried to use the code, you would see that it does what you asked for - Android Android
    • @AndroidAndroid Thank you, this is what you need! - Ivan Vovk

    Well, if all the options that were offered to you above are not suitable, then you can be distorted, this is a question of the layout technique. Something like that in your xml markup you add a RelativeLayout, three of which will be all your views, and on top of your content you add another RelativeLayout, you put a background on it with transparency, add it to the center of the ProgressBar and everything is ready, when you need to show you do relativeLayuot.setVisibility (View. VISIBLE) when you need to hide relativeLayuot.setVisibility (View.GONE).