728x90

Cutstom Dialog 기능을 이용하여 SMS authentication with One Time Password 처리를 위한 Layout 구성 예제이다.


custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/parent_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
        android:id="@+id/parent_card_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent">

        <RelativeLayout
            android:id="@+id/inner_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/transparent">

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/dialog_title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/default_title_text"
                android:textSize="20sp"
                android:textStyle="bold"
                android:textColor="@android:color/black"
                android:textAlignment="center"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="5dp"
                android:paddingBottom="2dp"/>

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/dialog_explain_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/dialog_title_text"
                android:text="@string/default_explain_text"
                android:textSize="14sp"
                android:textColor="@android:color/black"
                android:textAlignment="center"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="2dp"
                android:paddingBottom="5dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/et_auth_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/dialog_explain_text"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp" >

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/et_auth_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorWhite"
                    android:textSize="16sp"
                    android:hint="@string/prompt_auto"
                    android:inputType="numberDecimal"
                    android:imeOptions="actionDone"
                    android:selectAllOnFocus="true">

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

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

            <LinearLayout
                android:id="@+id/btn_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:layout_below="@id/et_auth_layout"
                android:gravity="top"
                android:orientation="horizontal">

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btn_disagree"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:layout_weight="1"
                    android:backgroundTint="@color/colorOrangeDark"
                    app:cornerRadius="10dp"
                    android:text="취소" />

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btn_agree"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_weight="1"
                    android:backgroundTint="@color/colorBlue"
                    app:cornerRadius="10dp"
                    android:text="전송" />

            </LinearLayout>
        </RelativeLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>
 


예제의 코드는 https://github.com/jsk005/JavaProjects/tree/master/Interfaces/src/main/java/com/link2me/android/interfaces 에 올려져 있다.

Custom Dialog 를 Interface로 처리하는 코드 예제일 뿐이지 SMS OTP 인증 전체 코드는 아니다.


728x90

'안드로이드 > Layout' 카테고리의 다른 글

LinearLayout 예제  (0) 2020.10.13
LinearLayout 동적 생성  (0) 2020.10.01
EditText DatePicker  (0) 2020.08.18
Floating Action Button  (0) 2020.07.11
CardView Layout 예제  (0) 2020.04.12
블로그 이미지

Link2Me

,