前几天公司的一个需求是选择日期并默认选中当天日期。当时想的是默认选中当天日期那肯定是点击TextView再选择日历咯。于是乎,在网上搜了一下。下面放一下效果图
选中日期的话我们可以用DatePickerDialog和DatePicker。下面我就用DatePickerDialog为例。
下面放代码~~~~
XML
<LinearLayout
android:id="@+id/down_choose_date"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/down_tv_choose_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="@dimen/dp_15"
android:text="2019/12/28"
android:textColor="@color/whit