自定义日期时间选择器在android中使用NumberPicker和FragmentDialog

时间:2016-02-09 15:25:40

标签: android fragment datetimepicker numberpicker dialogfragment

我想要一个完全如图所示的自定义日期时间选择器对话框。

在我的项目中,点击位于TextView的{​​{1}}时会显示对话框。我知道我需要使用NumberPickers填充日期从当前日期到下周的所有日期。

默认的android日期和时间选择器不适合我的要求所以我需要创建自己的自定义`DateTimePicker fragmentDialog'。

我需要的DateTimePicker

Please click here to view my required DateTimePicker

Fragment

编辑:好了,现在这就是我想要的,但现在我想在今天的日期之前禁用日期以及仅显示7天Ex。如果今天10日,那么在10日之前禁用所有日期并且显示日期仅为10,11,12,14,15,16,17。

<LinearLayout
android:background="@color/background_default_white"
style="@style/LinearPageLayout"
xmlns:android="http://schemas.android.com/apk/res/android">


<TextView
    android:textSize="20sp"
    android:textStyle="normal"
    android:textColor="@color/text_default_black"
    android:gravity="center"
    android:layout_gravity="center"
    android:id="@+id/custom_picker_title"
    android:background="@color/background_default_white"
    android:paddingLeft="15dp"
    android:layout_width="300dp"
    android:layout_height="45dp"
    android:text="@string/MessageChangeDateRange" />


<View
    android:visibility="visible" style="@style/Spliter" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="25dp">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">

        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_month"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">

        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />n 
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2.3">

        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_date_full"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">
        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_hour"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">
        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_minute"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0">
        <NumberPicker
            android:layout_gravity="center"
            android:id="@+id/custom_picker_ampm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>

<View style="@style/Spliter" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/custom_picker_set"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Set"
        style="@style/DefaultButtonFill" />
</LinearLayout>

}

0 个答案:

没有答案
相关问题