实施日历和时间选择器的最佳方法是什么?

时间:2019-01-04 06:28:05

标签: android kotlin datepicker timepicker

我必须实施CalendarTimePicker,并附上图片,请看一下并给出答案,这是实现此目的的最佳方法。

预先感谢

请看这张图片

enter image description here

1 个答案:

答案 0 :(得分:-1)

对于日期选择,您可以像使用xml一样使用HorizontalCalendarViewHorizentalCalendarView1

<devs.mulham.horizontalcalendar.HorizontalCalendarView
            android:id="@+id/calendarView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:textColorNormal="#bababa"
            app:textColorSelected="#FFFF"
            app:selectorColor="#c62828"  //default to colorAccent
            app:selectedDateBackground="@drawable/myDrawable"/>

HorizentalCalendatView1 xml代码

<com.view.calender.horizontal.umar.horizontalcalendarview.HorizontalCalendarView
        android:id="@+id/horizontalcalendarview"
        android:layout_width="match_parent"
        android:layout_height="200dp">
 </com.view.calender.horizontal.umar.horizontalcalendarview.HorizontalCalendarView>

,对于时间选择器,您可以使用androidTimePicker。也 wheel picker与此相关,您可以像这样设计时间选择器

<LinearLayout
        android:id="@+id/timepicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/calendarView"
        android:gravity="center_horizontal">
        <com.aigestudio.wheelpicker.WheelPicker
            android:id="@+id/hour"
            app:wheel_item_text_size="20sp"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            app:wheel_item_space="10dp"
            app:wheel_same_width="true"
            app:wheel_atmospheric="true"
            app:wheel_curved="true"
            app:wheel_cyclic="true"
            app:wheel_item_align="right"
            app:wheel_item_text_color="#A7A7DB"
            app:wheel_selected_item_text_color="#536D8A"
            app:wheel_visible_item_count="3"/>
        <View
            android:layout_width="15dp"
            android:layout_height="match_parent"/>
        <com.aigestudio.wheelpicker.WheelPicker
            android:id="@+id/minute"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            app:wheel_item_space="10dp"
            app:wheel_same_width="true"
            app:wheel_atmospheric="true"
            app:wheel_curved="true"
            app:wheel_cyclic="true"
            app:wheel_item_text_color="#A7A7DB"
            app:wheel_item_text_size="20sp"
            app:wheel_selected_item_text_color="#536D8A"
            app:wheel_visible_item_count="3"/>
        <View
            android:layout_width="15dp"
            android:layout_height="match_parent"/>
        <com.aigestudio.wheelpicker.WheelPicker
            android:id="@+id/am_pm"
            app:wheel_item_text_size="20sp"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            app:wheel_item_space="10dp"
            app:wheel_same_width="true"
            app:wheel_atmospheric="true"
            app:wheel_curved="true"
            app:wheel_item_align="right"
            app:wheel_item_text_color="#A7A7DB"
            app:wheel_selected_item_text_color="#536D8A"
            app:wheel_visible_item_count="2"
             />

</LinearLayout>