简体   繁体   English

Android 日历视图 - 如何自定义日历视图以使其像 Google 日历应用程序一样?

[英]Android Calendar View - How to customize Calendar View to make it like Google Calendar App one?

In recent Google Calendar App , it has a calendar which can be pulled down to show, and display in the style like this:在最近的Google Calendar App中,有一个可以下拉显示的日历,显示的样式是这样的:

在此处输入图片说明

I wanted to build a Calendar like this to the App, but when I put the android API CalendarView to the app, its style is very different:本来想给App建个这样的Calendar,但是当我把android API CalendarView放到app上的时候,它的风格就大不一样了:

在此处输入图片说明

So, the problem is how could I style/customize the CalendarView to like the one in Google Calendar App?所以,问题是我如何设计/自定义 CalendarView 以喜欢 Google Calendar App 中的那个?

Also, for Google Calendar App's calendar, when there is an event on a particulate, there will be "small dots" under the date text (Like the 19th and 21th of Augest in the above Google Calendar's image).另外,对于Google Calendar App的日历,当一个粒子上有事件时,日期文本下会出现“小圆点”(如上图Google Calendar图片中的8月19日和21日)。 How to achieve something like this, when I am having a list of dates (NOT events of android calendar, just a list of dates) and wanted to mark a dot on these dates on the Calendar, like what the Google Calendar App did?如何实现这样的事情,当我有一个日期列表(不是 android 日历的事件,只是一个日期列表)并想在日历上的这些日期上标记一个点,就像谷歌日历应用程序所做的那样?

I wanted to build a Calendar like this to the App我想为应用程序构建这样的日历

You can use This Library to achieve what you want.您可以使用此库来实现您想要的。

In recent Google Calendar App , it has a calendar which can be pulled down to show在最近的 Google Calendar App 中,它有一个可以下拉显示的日历

You can hide/show your calendar view using animations.您可以使用动画隐藏/显示日历视图。

there will be "small dots" under the date text日期文本下会有“小点”

I've achieved this using this library but you need to study it a bit and modify it.This is using a canvas to build the calendar view and You can add circles on your dates using the x,y coordinates of these dates.Just pass the dates to this lib and use drawCircle() method for canvas.我已经使用这个库实现了这一点,但您需要对其进行一些研究并对其进行修改。这是使用画布来构建日历视图,您可以使用这些日期的 x、y 坐标在您的日期上添加圆圈。只需通过这个库的日期并使用画布的drawCircle()方法。

I have found one project which create dropdown view like Google calendar app我找到了一个创建下拉视图的项目,如Google calendar应用程序

Use this : Sample Project使用这个:示例项目

Which is use CollapsingToolbarLayout inside it put custom calenderView which set dots on event date also it copy of google calendar app这是使用CollapsingToolbarLayout在里面放置自定义日历CollapsingToolbarLayout ,它在事件日期设置点也是谷歌日历应用程序的副本

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@animator/ann"
        app:expanded="false"
        android:background="@android:color/white"
        app:layout_behavior=".MyAppBarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
            app:statusBarScrim="?attr/colorPrimaryDark">

            <!--large view -->
            <com.example.GoogleCalendar.GooglecalenderView
                android:id="@+id/calander"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:orientation="vertical"
                app:layout_collapseMode="pin"

                android:layout_marginTop="?attr/actionBarSize"
              >


            </com.example.GoogleCalendar.GooglecalenderView>

            <!--top toolbar-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:title="fkdl"
                app:contentInsetLeft="0dp"
                app:contentInsetStart="0dp"
                app:titleTextColor="@color/colorPrimaryDark"
                android:background="@android:color/white"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:clickable="true"
                    android:focusable="true">

                    <View
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginTop="10dp"
                        android:id="@+id/backsupport"
                        android:background="?attr/selectableItemBackground"
                        android:clickable="true"
                        android:layout_marginBottom="10dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                <TextView
                        android:id="@+id/monthname"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="4dp"
                        android:paddingBottom="4dp"
                        android:fontFamily="@font/googlesans_regular"
                        android:text="June"
                        android:textColor="#464646"
                        android:textSize="20sp" />
                    <ImageView
                        android:id="@+id/arrowImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_arrow_drop_up_black_24dp"
                        app:layout_constraintLeft_toRightOf="@+id/monthname"
                        android:translationX="-5dp"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        tools:ignore="ContentDescription,RtlHardcoded" />
                                 </android.support.constraint.ConstraintLayout>

            </android.support.v7.widget.Toolbar>
  </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <com.example.GoogleCalendar.MyRecyclerView
        android:id="@+id/nestedView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</android.support.design.widget.CoordinatorLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM