Kayan Almeida
Kayan Almeida

Reputation: 611

Progress Dialog without padding

I'm using a simple Progress Dialog generator method inside a Fragment:

public void showProgressDialog(int messageId){
    String message = getString(messageId);
    mProgressDialog = ProgressDialog.show(this.getActivity(), "", message, true);
}

My Progress Dialog appears like this, without that normal padding: Progress Dialog

What should I do to have that default padding around my progress bar?

EDIT: Adding themes.xml file

<resources xmlns:tools="http://schemas.android.com/tools">

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
</style>

<style name="AppTheme" parent="AppBaseTheme">

    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

    <item name="android:windowContentOverlay">@null</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>

    <!-- Toolbar Theme / Apply white arrow -->
    <item name="colorControlNormal">@android:color/white</item>
    <item name="actionBarTheme">@style/AppTheme.ActionBarTheme</item>

    <!-- Material Theme -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/status_bar_color</item>
    <item name="colorAccent">@color/accent_color</item>

    <item name="android:navigationBarColor" tools:targetApi="21">@color/navigationBarColor</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="21">true</item>

</style>

<style name="AppTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
    <!-- White arrow -->
    <item name="colorControlNormal">@android:color/white</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@color/drawerArrowColor</item>
</style>
</resources>

This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress. For more details Link

Upvotes: 3

Views: 905

Answers (4)

Anatoly
Anatoly

Reputation: 49

I had the same issue while using <item name="android:fitsSystemWindows">true</item> in my app theme. Deleting this item helped me (actually, just moved it in other parts of my code).

Upvotes: 0

user3567234
user3567234

Reputation: 41

This is my solution method,create a new theme for the Dialog. Hope it will help you!

   <style name="ProgressDialogTheme" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:fitsSystemWindows">false</item>
        <item name="android:clipToPadding">false</item>
    </style>

    ProgressDialog progressDialog = new ProgressDialog(context, R.style.ProgressDialogTheme);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(content);
    progressDialog.show();

Upvotes: 4

KishuDroid
KishuDroid

Reputation: 5451

Yuu can try below code:

        ProgressDialog dialog = new ProgressDialog(getActivity(), getTheme());
        dialog.setTitle(getString(R.string.pleaseWait));
        dialog.setMessage(getString(R.string.message));
        dialog.setIndeterminate(true);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

You can set different theme for your progressdialog..

1) Try ProgressDialog.THEME_HOLO_DARK instead of getTheme().

2) Or you can set custom theme. See thi link .

For more details. See this link.

Hope it will help you.

Upvotes: 0

Aditya Vyas-Lakhan
Aditya Vyas-Lakhan

Reputation: 13555

Try this way

 pDialog = new ProgressDialog(getActivity());
            pDialog.setMessage("Loading...");
            pDialog.setIndeterminate(true);
           // (To customize your dialog)pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress));
            pDialog.setCancelable(false);
            pDialog.show();

Upvotes: 1

Related Questions