Android 如何在我的DialogFragment中显示进度条?

Android 如何在我的DialogFragment中显示进度条?,android,progress-bar,android-dialogfragment,Android,Progress Bar,Android Dialogfragment,我已经在我的布局中创建了dialogfragment,我已经添加了Progressbar,需要在我的对话框片段中可见。但它在我的对话片段中没有被检测到 这是我的布局 <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"&

我已经在我的布局中创建了dialogfragment,我已经添加了Progressbar,需要在我的对话框片段中可见。但它在我的对话片段中没有被检测到

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#99ffffff">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="30dp"
        android:background="@color/white"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity"
            android:text="@string/invite_consumer"
            android:textColor="@color/veryDarkGrey"
            android:textSize="@dimen/button_text_size"
            app:font="@{@string/font_roboto_bold}" />


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/top"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="10dp">
                    <!--din 77-->
                    <EditText
                        android:id="@+id/firstName"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/first_name"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/surname"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/surname"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/email"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/email"
                        android:imeOptions="actionNext"
                        android:inputType="textEmailAddress"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/mobile"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/mobile_number"
                        android:inputType="phone"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/vehicleId"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/vehicle_id"
                        android:imeOptions="actionDone"
                        android:lines="1"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />
                    <!--din 49-->
                </LinearLayout>

                <Button
                    android:id="@+id/submit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/top"
                    android:layout_marginTop="@dimen/activity"
                    android:background="@drawable/sel_rounded_rectangular_yellow"
                    android:gravity="center"
                    android:minHeight="@dimen/min_touch"
                    android:text="@string/submit"
                    android:textAllCaps="false"
                    android:textColor="@color/white"
                    android:textSize="@dimen/button_text_size"
                    app:font="@{@string/font_roboto_regular}" />
            </RelativeLayout>

        </ScrollView>

    </LinearLayout>

    <ProgressBar
    android:id="@id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="visible"/>
</RelativeLayout>
在这里,我需要像打电话一样显示progressbar mBinding.progressBar.setVisibility(View.VISIBLE); 但它不允许这样称呼。
任何关于调用progressbar的建议我认为id声明有问题

改变

android:id=“@id/progressBar” 到android:id=“@+id/progressBar”


试试看这里的问题是什么。。。当您显示对话框时,进度条不可见?是的,即使我也不能称之为mBinding.progressBar.setVisibility(View.visible);如果我调用了此命令,则无法解析此消息,显示我如何将可见设置为progressbar?您是否已将android:id=“@id/progressbar”更改为android:id=“@+id/progressbar”并重试。。。是的,这对我来说太疯狂了。。谢谢,有时候会发生;)
public class PopupInviteConsumerDialog extends BaseDialog implements View.OnClickListener {
private InviteConsumerDialogBinding mBinding;
private Context mContext;

public static PopupInviteConsumerDialog newInstance(Context context) {
    PopupInviteConsumerDialog dialog = new PopupInviteConsumerDialog();
    dialog.mContext = context;
    return dialog;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);

    mBinding = DataBindingUtil.inflate(inflater, R.layout.invite_consumer_dialog, container, false);

    setCancelable(false);
mBinding.progressBar.setVisibility(View.VISIBLE);
    mBinding.submit.setOnClickListener(this);

    return mBinding.getRoot();
}

@Override
public void onStart() {
    super.onStart();
    getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.submit:
            submit();
            break;
    }
}

@Override
public Dialog onCreateDialog(@NonNull Bundle savedInstanceState) {
    return new Dialog(getActivity(), getTheme()) {
        @Override
        public void onBackPressed() {
            dismiss();
        }
    };
}