如何使对话框像活动一样调整大小?

时间:2019-09-14 16:47:26

标签: android android-alertdialog adjustpan

这里是我的代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"
>
    <LinearLayout

            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="16dp"
            android:orientation="vertical">


        <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/tv_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Sign Up"
                fontPath="fonts/opensans.ttf"

                android:padding="10dp"
                android:textAllCaps="true"
                android:textSize="20dp"
                android:textColor="@android:color/white"
        />


        <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/f_name"
                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/first_name"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_f_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    fontPath="fonts/opensans.ttf"
                    android:imeOptions="flagNoFullscreen"
                    android:maxLines="1"/>

        </com.google.android.material.textfield.TextInputLayout>


        <com.google.android.material.textfield.TextInputLayout
                android:layout_marginTop="10dp"
                android:id="@+id/l_name"

                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/last_name"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_l_name"
                    android:gravity="start"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:maxLines="1"
                    fontPath="fonts/opensans.ttf"

                    android:textColor="@android:color/white"
            />

        </com.google.android.material.textfield.TextInputLayout>


        <com.google.android.material.textfield.TextInputLayout
                android:layout_marginTop="10dp"
                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/state"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_state"
                    android:maxLines="1"
                    android:gravity="start"
                    fontPath="fonts/opensans.ttf"

                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
            />

        </com.google.android.material.textfield.TextInputLayout>


        <com.google.android.material.textfield.TextInputLayout
                android:layout_marginTop="10dp"
                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/email_id"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_email"
                    android:maxLines="1"
                    android:gravity="start"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
                    fontPath="fonts/opensans.ttf"

            />

        </com.google.android.material.textfield.TextInputLayout>


        <com.google.android.material.textfield.TextInputLayout
                android:layout_marginTop="10dp"
                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/mobile_number"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_mobile_number"
                    android:gravity="start"
                    android:maxLines="1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="@android:color/white"
                    fontPath="fonts/opensans.ttf"

            />

        </com.google.android.material.textfield.TextInputLayout>


        <LinearLayout
                android:visibility="gone" android:layout_width="match_parent" android:layout_height="wrap_content"
                android:orientation="horizontal">


            <com.google.android.material.textfield.TextInputLayout
                    android:layout_marginTop="10dp"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    android:layout_width="0dp"
                    android:layout_weight="0.7"
                    android:layout_height="wrap_content"
                    android:hint="@string/enter_otp">

                <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/et_otp"
                        android:gravity="start"
                        android:maxLines="1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"/>

            </com.google.android.material.textfield.TextInputLayout>


            <androidx.appcompat.widget.AppCompatButton
                    android:id="@+id/btn_verify"
                    android:layout_marginTop="5dp"
                    android:layout_gravity="center"
                    android:layout_marginEnd="2dp"
                    android:layout_marginStart="2dp"
                    android:layout_width="0dp"
                    android:layout_weight="0.3"
                    android:layout_height="wrap_content"
                    android:background="#009688"
                    android:text="Get OTP"
                    android:padding="10dp"
                    android:textColor="@android:color/white"/>


        </LinearLayout>


        <com.google.android.material.textfield.TextInputLayout
                android:layout_marginTop="10dp"
                style="@style/LoginTextInputLayoutStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/company_name"
                android:textColorHint="#fff"
                app:boxStrokeColor="#fff"
                app:errorEnabled="true"
                android:backgroundTint="#fff">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_company"
                    android:gravity="start"
                    android:maxLines="1"
                    android:textColor="@android:color/white"
                    fontPath="fonts/opensans.ttf"

                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

        </com.google.android.material.textfield.TextInputLayout>


        <androidx.appcompat.widget.AppCompatButton
                android:id="@+id/btn_continue"
                android:layout_marginEnd="2dp"
                android:layout_marginStart="2dp"
                android:layout_marginTop="56dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Continue"
                fontPath="fonts/opensans.ttf"

                android:padding="20dp"
                android:layout_marginBottom="30dp"
                android:background="@drawable/bg_tv"
                android:textColor="@android:color/white"/>

    </LinearLayout>
</androidx.core.widget.NestedScrollView>

注意:我尝试了对话框?.window?.setSoftInputMode(                 WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

 private fun showLoginDialog(i: Int) {



        dialog = Dialog(this, android.R.style.Theme_Light_NoTitleBar_Fullscreen)

        //        dialog!!.window.setBackgroundDrawableResource(android.R.color.transparent)

        dialog?.setCancelable(true)
        dialog?.setTitle("Please Fill following information to download file.")
        dialog?.setContentView(R.layout.activity_login)
        dialog?.window?.setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
        dialog?.show()
}

0 个答案:

没有答案