Android: how to display a full screen progress bar in the center

I'm trying to display the progress bar with a custom theme. But it's in the upper left corner instead of the center. If I don't use a custom theme, it will be displayed in the center, but not in full screen, which will show the text view and other elements in the background. It looks terrible. Here's the code and screenshot

Custom theme:

<?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">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

In the activity initialization progress dialog box with a custom theme:

progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog);
progressBar.setMessage("Please wait...");
progressBar.setCancelable(false);

When I see the preview of the progress bar theme alone, it displays correctly as follows. However, it displays the wrong position in the activity

resolvent:

You are passing the ID of the layout in the constructor that requires the topic ID

progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog);

Constructor is

public ProgressDialog(Context context, int theme) 

You should define custom attributes in style. XML and pass the ID of the style here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>