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

TextInputLayout in Sketchware

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

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation