Reputation: 486
I am using the following code to add a progress dialog:
progress_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:windowIsFloating="false"
android:background="@android:color/white">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java
public void onProgressChanged(WebView view, int progress) {
if (mProgress == null) {
mProgress = new ProgressDialog(MainActivity.this);
// Setting progress dialog color as transparent
mProgress.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
mProgress.show();
mProgress.setContentView(R.layout.progress_dialog);
mProgress.setCancelable(false);
mProgress.setCanceledOnTouchOutside(false);
// Added to prevent touch interaction while loading
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
// WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
// Setting text on progress bar
// mProgress.setMessage("Loading " + String.valueOf(progress) + "%");
if (progress == 100) {
mProgress.dismiss();
mProgress = null;
// Resume touch interaction once loaded
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
}
This shows the progress dialog as seen below:
I want the progress dialog to cover the entire screen as seen below:
How to accomplish this with ProgressDialog
?
Upvotes: 2
Views: 599
Reputation: 1195
This is good but I suggest you to use this into a different class for future when ever you need this just call the class name and implement this
public class ShowDialogClass {
public static ProgressDialog showDialog(Context context) {
final Dialog dialog = new Dialog(context, R.style.CustomDialogTheme);//apply style here
View view = LayoutInflater.from(context).inflate(R.layout.progress, null);// inflate the custom view
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT; // set as full width
params.height = WindowManager.LayoutParams.MATCH_PARENT;// set as full height
dialog.setContentView(view); //add the custom view
dialog.getWindow().setGravity(Gravity.CENTER); // set center gravity
return dialog;
}
}
and how you can use this like :
Dialog dialog= ShowDialogClass.showDialog(this)
dialog.show()
dialog.dismiss()
Upvotes: 1
Reputation: 2677
Try with this :
First you have to create theme in style file like below :
<style name="CustomDialogTheme" parent="Theme.AppCompat.Light.DialogWhenLarge">
<item name="android:windowIsFloating">false</item>
<item name = "android:windowBackground" >@android:color/white</item >
</style>
in the style above I put white dim background
And apply this style in your Dialog in java Code :
@SuppressLint("InflateParams")
private void showDialog() {
final Dialog dialog = new Dialog(this, R.style.CustomDialogTheme);//apply style here
View view = LayoutInflater.from(this).inflate(R.layout.progress, null);// inflat the custom view
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT; // set as full width
params.height = WindowManager.LayoutParams.MATCH_PARENT;// set as full heiggt
dialog.setContentView(view); //add the custom view
dialog.getWindow().setGravity(Gravity.CENTER); // set center gravity
dialog.show();
}
and finally this is the Custom layout :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
Upvotes: 2
Reputation: 249
set width and height to match_parent in progressbar.
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true" />
Upvotes: 0