如何在DialogFragment中显示进度条?

时间:2017-08-21 06:42:24

标签: 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">

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

我的dialogFragment就像这样

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();
        }
    };
}

在这里,我需要像调用一样显示进度条 mBinding.progressBar.setVisibility(View.VISIBLE); 但它不允许这称呼它。 任何调用进度条的建议

1 个答案:

答案 0 :(得分:1)

我认为id声明问题

更改

<强>机器人:ID =&#34; @ ID /进度&#34; android:id =&#34; @ + id / progressBar&#34;

并尝试