Search code examples
javaandroidandroid-layoutcalendarandroid-calendar

Android: How to get the Calendar in YEAR/MONTH/DATE Spinners


In my Android app, I am trying to get the birthday of the user. Below is my XML document .

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/colorPurple"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            style="@style/MyDrawerArrowToggle"
            android:layout_marginTop="@dimen/toolbar_layout_top_margin">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="30dp"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:gravity="center">

                    <ImageView
                        android:id="@+id/signUp_back_button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/back_arrow_white" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="220dp"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:textSize="20dp"
                        android:text="@string/birthday"
                        android:textColor="@color/colorWhite"
                        android:gravity="center|left"
                        android:paddingLeft="20dp"/>

                </LinearLayout>

            </LinearLayout>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:textStyle="bold"
                android:text="@string/what_is_your_birthday"
                android:gravity="center"
                android:layout_marginTop="60dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="30dp">

                <DatePicker
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:datePickerMode="spinner"
                    android:id="@+id/date_picker"/>



                <!--<com.aigestudio.wheelpicker.widgets.WheelDayPicker-->
                <!--android:layout_width="50dp"-->
                <!--android:layout_height="match_parent" />-->

                <!--<com.aigestudio.wheelpicker.widgets.WheelMonthPicker-->
                <!--android:layout_width="50dp"-->
                <!--android:layout_height="match_parent"-->
                <!--android:layout_marginLeft="20dp"/>-->

                <!--<com.aigestudio.wheelpicker.widgets.WheelYearPicker-->
                <!--android:layout_width="50dp"-->
                <!--android:layout_height="match_parent"-->
                <!--android:layout_marginLeft="20dp"/>-->

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@color/colorPurple"
                android:layout_marginTop="40dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/signup_birthday_next_button_layout">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text = "@string/next_text"
                    android:textColor="@color/colorWhite"
                    android:textSize="14dp"/>

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

This gives me the below UI

enter image description here

But I am looking for the below

enter image description here

How can I get the second UI?


Solution

  • Please add this xml file it may be help full to solve your problem.

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        <TextView
            android:gravity="center"
            android:id="@+id/btnNotification"
            android:text="What is your birthday"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <DatePicker
            android:id="@+id/spinnerDatePicker"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:calendarViewShown="false"
            android:datePickerMode="spinner"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:spinnersShown="true" />
    
        <Button
            android:text="next"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>