android中的DatePicker:箭头没有显示

时间:2014-06-11 07:24:36

标签: android datepicker

我遇到了DatePicker的问题:我在普通布局中使用它,而不是在片段或对话框中。这是布局(我有两个,这是其中之一):

 <DatePicker
 android:id="@+id/historic_fin_datepicker"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/historic_separator2"
 android:layout_centerInParent="true"
 android:calendarViewShown="false" >

问题是在应用程序中,未显示DatePicker的典型箭头

这些是我使用datepickers的活动方法。

/* OWN METHODS */
private void initializeUIFields() {
    seeHistoricButton = (RelativeLayout) findViewById(R.id.historic_see_layout);
    seeHistoricButton.setOnClickListener(this);
    datep_ini = (DatePicker) findViewById(R.id.historic_ini_datepicker);
    datep_fin = (DatePicker) findViewById(R.id.historic_fin_datepicker);
    setCurrentDate();

}

/** This method set the date of the both datepickers to the actual date */
public void setCurrentDate() {

    final Calendar calendar = Calendar.getInstance();

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    // set current date into Date Picker
    datep_ini.init(year, month, day, null);
    datep_fin.init(year, month, day, null);

}
/* This manage the button, if it is clicked, this method gets the date of the datepicker and go to a new activity */
@Override
public void onClick(View v) {
    int year, month, day;

    year = datep_ini.getYear();
    month = datep_ini.getMonth() + 1;
    day = datep_ini.getDayOfMonth();
    date_ini = day + "-" + month + "-" + year;

    year = datep_fin.getYear();
    month = datep_fin.getMonth() + 1;
    day = datep_fin.getDayOfMonth();
    date_fin = day + "-" + month + "-" + year;

    goToHistoricDetailView();
}

我想知道它是否与使用Fragment或Dialog相关。任何帮助都会很棒。

我为Android 4.4.2构建了项目,我正在使用Android 4.4.2的智能手机进行测试

完成布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/continue_button_height" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/field_margin_small"
        android:layout_marginRight="@dimen/field_margin_small"
        android:orientation="vertical" >

        <!-- Stard Date Layout -->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/historic_ini_title"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/field_title_area"
                android:layout_alignLeft="@+id/historic_ini_datepicker"
                android:layout_marginTop="@dimen/field_margin_small"
                android:orientation="horizontal" >

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <ImageView
                        android:layout_width="@dimen/historic_calendar_size"
                        android:layout_height="@dimen/historic_calendar_size"
                        android:layout_centerVertical="true"
                        android:contentDescription="@string/historic_calendar_img"
                        android:src="@drawable/historic_date_icon" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/historic_ini_date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:fontFamily="sans-serif-bold"
                        android:text="@string/historic_ini_date"
                        android:textColor="@color/sky_blue"
                        android:textSize="@dimen/field_title" />
                </RelativeLayout>
            </LinearLayout>

            <ImageView
                android:id="@+id/historic_separator1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/historic_ini_title"
                android:layout_marginBottom="@dimen/field_margin_small"
                android:contentDescription="@string/separator_blue"
                android:src="@drawable/horizontal_blue_separator" />

            <DatePicker
                android:id="@+id/historic_ini_datepicker"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/historic_separator1"
                android:layout_centerInParent="true"
                android:calendarViewShown="false"
                android:spinnersShown="true" >
            </DatePicker>
        </RelativeLayout>

        <!-- End Date Layout -->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/historic_fin_title"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/field_title_area"
                android:layout_alignLeft="@+id/historic_fin_datepicker"
                android:layout_marginTop="@dimen/field_margin_small"
                android:orientation="horizontal" >

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <ImageView
                        android:layout_width="@dimen/historic_calendar_size"
                        android:layout_height="@dimen/historic_calendar_size"
                        android:layout_centerVertical="true"
                        android:contentDescription="@string/historic_calendar_img"
                        android:src="@drawable/historic_date_icon" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/historic_fin_date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:fontFamily="sans-serif-bold"
                        android:text="@string/historic_fin_date"
                        android:textColor="@color/sky_blue"
                        android:textSize="@dimen/field_title" />
                </RelativeLayout>
            </LinearLayout>

            <ImageView
                android:id="@+id/historic_separator2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/historic_fin_title"
                android:layout_marginBottom="@dimen/field_margin_small"
                android:contentDescription="@string/separator_blue"
                android:src="@drawable/horizontal_blue_separator" />



            <DatePicker
                android:id="@+id/historic_fin_datepicker"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/historic_separator2"
                android:layout_centerInParent="true"
                android:calendarViewShown="false" >
            </DatePicker>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

<RelativeLayout
    android:id="@+id/historic_see_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/continue_button_height"
    android:layout_alignParentBottom="true"
    android:background="@color/sky_blue"
    android:clickable="true"
    android:fontFamily="sans-serif-light" >

    <TextView
        android:id="@+id/historic_see"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:fontFamily="sans-serif"
        android:text="@string/historic_see"
        android:textColor="@color/white"
        android:textSize="@dimen/continue_button_text" />
</RelativeLayout>

我尝试使用DialogFragment,就像在Android Developers Guide中一样,但即便如此,我也看不到箭头。

1 个答案:

答案 0 :(得分:-2)

试试这个

  <DatePicker
                android:id="@+id/historic_fin_datepicker"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/historic_separator2"
                android:layout_centerHorizontal="true"
                android:calendarViewShown="false" >