如何在自定义应用程序中使用Android Stock Calendar中的视图(月,日,周)

Mah*_*him 8 android android-source android-xml android-view

在Google Stock Android日历中存在多个视图(月,周,议程,周),从Google Android Sources Repositories下载的源代码具有相同的应用程序,通过探索代码,命名包com.android.calendar具有负责呈现这些活动的主视图:

在此输入图像描述

通过努力解决代码,我使用了两个包com.android.calendar.month,com.android.calendar但无法实现我的目标,这是我使用的示例:

在此输入图像描述

以及主要的以下代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)

这是我的xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/month"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:paddingTop="1dip"
    android:background="@null">

    <TextView android:id="@+id/month_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dip"
        android:visibility="gone"
        style="@style/MonthView_MiniMonthLabel" />

    <include android:id="@+id/day_names" layout="@layout/full_month_header" />

     <View
        android:background="@color/calendar_grid_line_inner_vertical_color"
        android:layout_height="1px"
        android:layout_width="match_parent" />

    <com.android.calendar.month.MonthListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawSelectorOnTop="false" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

直到这里代码工作正常,但有一个空白的白色屏幕和一个操作栏,如果我的问题不明确请尝试编辑它.

What should be done to include Calendar Views (Month, Week, Day) in a custom application ?
Run Code Online (Sandbox Code Playgroud)

don*_*uxx 2

您应该看看CalendarView,它是在 Android 中集成日历的标准方式。

另外,如果您需要在 UI 中选择日期和时间,可以使用DatePickerTimePicker

请记住,Android 中的默认日历应用程序是开源的!请随意深入研究这里的代码