Widget - ProgressDialog Transparent

//Add Private

private int progressStatus = 0;
private Handler handler = new Handler();

//Add on Button
// Initialize a new instance of progress dialog
final ProgressDialog pd = new ProgressDialog(MainActivity.this);

// Set progress dialog style horizontal
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

// Set the progress dialog background color transparent
pd.getWindow().setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(Color.TRANSPARENT));

pd.setIndeterminate(false);

// Finally, show the progress dialog
pd.show();

// Set the progress status zero on each button click
progressStatus = 0;

// Start the lengthy operation in a background thread
new Thread(new Runnable() {
@Override
public void run() {
while(progressStatus < 100){
// Update the progress status
progressStatus +=1;

// Try to sleep the thread for 20 milliseconds
try{
Thread.sleep(20);
}catch(InterruptedException e){
e.printStackTrace();
}

// Update the progress bar
handler.post(new Runnable() {
@Override
public void run() {
// Update the progress status
pd.setProgress(progressStatus);
// If task execution completed
if(progressStatus == 100){
// Dismiss/hide the progress dialog
pd.dismiss();
}
}
});
}
}
}).start(); // Start the operation

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key