SoFunction
Updated on 2025-03-01

Android realizes pop-up progress bar effect

Android custom progress bar mainly modifies the style of the ProgressBar, and pop-up window displays the ProgressBar in the Dialog.

Directly upload the code.

Add the following code to it:

<style name="ProgressBar_Mini" parent="@android:style/"> 
  <item name="android:maxHeight">50dip</item> 
  <item name="android:minHeight">8dip</item> 
  <item name="android:indeterminateOnly">false</item> 
  <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> 
  <item name="android:progressDrawable">@drawable/progressbar_mini</item> 
</style> 
<style name="dialog" parent="@android:style/"> 
  <item name="android:windowFrame">@null</item> 
  <item name="android:windowIsFloating">true</item> 
  <item name="android:windowIsTranslucent">true</item> 
  <item name="android:windowNoTitle">true</item> 
  <item name="android:backgroundDimEnabled">true</item> 
  <item name="android:windowBackground">@color/transparent</item> 
 </style> 

The content of the newly created drawable/progressbar_mini.xml is as follows:

<layer-list xmlns:andro > 
 <item android:> 
  <shape> 
   <corners android:radius="0dip" /> 
   <gradient 
    android:angle="270" 
    android:centerY="0.75" 
    android:endColor="#F5F5F5" 
    android:startColor="#BEBEBE" /> 
  </shape> 
 </item> 
 
 <item android:> 
  <clip> 
   <shape> 
    <corners android:radius="0dip" /> 
    <gradient 
     android:angle="270" 
     android:centerY="0.75" 
     android:endColor="#165CBC" 
     android:startColor="#85B0E9" /> 
   </shape> 
  </clip> 
 </item> 
 
 <item android:> 
  <clip> 
   <shape> 
    <corners android:radius="0dip" /> 
    <gradient 
     android:angle="270" 
     android:centerY="0.75" 
     android:endColor="#00FF66" 
     android:startColor="#00FF66" /> 
   </shape> 
  </clip> 
 </item> 
</layer-list> 

The contents are as follows:

&lt;?xml version="1.0" encoding="utf-8"?&gt; 
&lt;LinearLayout xmlns:andro 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="@drawable/back_qian" 
 android:gravity="center" 
 android:orientation="vertical" &gt; 
 
 &lt;TextView 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:gravity="center" 
  android:text="Switching status..." 
  android:textSize="18sp" 
  android:textColor="@color/black" /&gt; 
 
 &lt;TextView 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:gravity="center" 
  android:text="" /&gt; 
 
&lt;ProgressBar 
 android:  
 style="@style/ProgressBar_Mini" 
 android:layout_width="290dp" 
 android:layout_height="17dp" /&gt; 
  
&lt;/LinearLayout&gt; 

The contents are as follows:

package ; 
 
import ; 
import ; 
import ; 
import ; 
import ; 
import ; 
import ; 
 
import ; 
 
public class MyProgressBar { 
 Dialog dialog; 
 Context context; 
 // Declare ProgressBar object private ProgressBar pro1; 
  
 
 /**
   * Construct
   */ 
 public MyProgressBar(Context context) { 
  // TODO Auto-generated constructor stub 
   = context; 
  dialog = new Dialog(context, ); 
  (onCancelListener); 
 } 
 
 /**
   * Initialization progress dialog box
   */ 
 public void initDialog() { 
 
  LayoutInflater inflater = (LayoutInflater) context 
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  View view = (, null); 
  (view); 
  pro1 = (ProgressBar) (.progressBar1); 
  // Set whether the progress bar rotates automatically, that is, set its uncertain mode. False means no automatic rotation  (false); 
  // Set the maximum value of ProgressBar  (100); 
 
  // Set the current value of ProgressBar  (0); 
 
   
  (); 
 } 
 
 public void setProgress(int progressValue) { 
  (progressValue); 
 } 
  
 public void colseDialog() { 
  (); 
 } 
 
 public boolean isShowing() { 
  if (()) { 
   return true; 
  } else { 
   return false; 
  } 
 } 
 
 OnCancelListener onCancelListener = new OnCancelListener() { 
  @Override 
  public void onCancel(DialogInterface dialog) { 
   // TODO Auto-generated method stub 
   (); 
  } 
 }; 
} 

The call code is as follows:

MyProgressBar myProgressBar; 
myProgressBar = new MyProgressBar(Dialog_TestActivity.this); 
(); 
    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
 
 
      try { 
       (200); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       (); 
      } 
      for (int i = 0; i &lt; 100; i++) { 
       (0); 
       try { 
        (30); 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        (); 
       } 
      } 
     } 
    }).start(); 
Handler handler = new Handler() { 
  @Override 
  public void handleMessage(Message msg) { 
   // Change the current value of ProgressBar   (intCounter++); 
   if (intCounter == 100) { 
    intCounter = 0; 
    (); 
   } 
  }  
 }; 

Press Return to exit:

@Override 
 public void onBackPressed() { 
  // TODO Auto-generated method stub 
  ("11", "onBackPressed()"); 
 
  if (()) { 
   (); 
  } 
  if (()) { 
   (); 
  } 
 
  (); 
 } 

Source code:Android implementation pop-up progress bar

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.