Android 为什么datepicker在我的视图中添加日历?

Android 为什么datepicker在我的视图中添加日历?,android,android-layout,android-calendar,Android,Android Layout,Android Calendar,我开始学习如何在Android上开发。这是非常简单的,但我面临的一个问题,我没有发现任何地方提到 我有一个看法: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_p


我开始学习如何在Android上开发。这是非常简单的,但我面临的一个问题,我没有发现任何地方提到

我有一个看法:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">

    <EditText
        android:id="@+id/editNomProduit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/ht_nom_produit" />



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal">

        <TextView
            android:id="@+id/labelQuantiteProduitEdit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/labelQuantiteProduitEdit"
            android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
        android:id="@+id/editQuantite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number" />

<Spinner
    android:id="@+id/spinnerUnite"
    android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal">

        <TextView
            android:id="@+id/labeDateAchatProduitEdit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/labelDateAchatProduitEdit"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <DatePicker
            android:id="@+id/dpDateAchatProduit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

它显示了一个日期选择器。问题是,日期选取器似乎除了为日期选取器添加了经典的滚轮之外,还添加了一个日历(见图)。我不想看到这样的景象,只想看日期。我是否以错误的方式使用日期选择器,或者这是原始行为? 谢谢

纪尧姆


将此行添加到日期选择器xml中

android:calendarViewShown="false"

这将删除日历。

您需要在下面添加的所有内容:

 <datepicker>
这将删除日历,但保留滚动条


希望这有帮助

我也有同样的问题。我还没有创建任何xml文件。因此,我通过在Activity中更改
calendarviewshow
的值进行了修复。希望它能帮助别人

我们可以使用两种方法在
DatePicker
中隐藏日历视图

布局(XML文件)中有1个(感谢@coconess)


将日期选择器从xml更改为:

添加

而不是

android:calenderViewShown="false"

这确实帮了大忙!感谢我的荣幸,很高兴如果您编写
android:datePickerMode=“spinner”
,它可以帮助编辑。我只想补充一点,API 11及以上版本都可以使用此选项。您如何通过编程实现这一点(当选择器是使用代码创建的,并且没有XML时?)在API级别>=24下?SetCalendarViewShowed在API版本24中不推荐使用,现在呢?
<DatePicker
    android:id="@+id/datepickerv1"
    android:calendarViewShown="false">
Note: If you are not using "calendarViewShow" in xml, follow this step.
DatePicker dp=(DatePicker)findViewById(R.id.datepickerv1);
dp.setCalendarViewShown(false);
android:datePickerMode="spinner"
android:calenderViewShown="false"