像IOS一样的安卓年历

标签 android ios iphone calendar android-calendar

我想像 ios 一样在 Android 中创建年历

比如这张照片。 带有年、月和日。

我用 2 个 ListView 和 1 个 GridView 来做,但是,我在年份项目之间有滞后。

50 年。有 12 个月的文本。


enter image description here

最佳答案

看这个例子..

https://github.com/ik024/CalendarLibrary

对于 YearView(这显示两列请检查此代码如何设置两列而不是满足您的要求)

enter image description here

在您的 xml 文件中添加以下内容:

 <com.github.ik024.calendar_lib.YearView 
    android:id="@+id/calendar_year_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"/>

在您的 Activity 中实现 YearViewClickListener:

public class MonthViewDemo extends AppCompatActivity implements YearViewClickListeners{


@Override
public void dateClicked(int year, int month, int day) {
    Toast.makeText(this, "year: "+year+";\nmonth: "+month+";\nday: "+day, Toast.LENGTH_LONG).show();
    //TODO: Perform your actions based on year or month or day clicked
  }


}

更多内容请引用 YearViewDemo.java 文件。

自定义

可以自定义以下属性:

<attr name="currentDayTextColorYV" format="color"/>
<attr name="monthNameTextColorYV" format="color"/>
<attr name="daysOfMonthTextColorYV" format="color"/>
<attr name="daysOfWeekTextColorYV" format="color"/>
<attr name="eventDayBackgroundColorYV" format="color"/>
<attr name="eventDayTextColorYV" format="color"/>
<attr name="calendarBackgroundColorYV" format="color" />
<attr name="monthNameBackgroundColorYV" format="color" />
<attr name="displayYearTextColorYV" format="color" />
<attr name="headerBackgroundColorYV" format="color" />
<attr name="prevButtonBackgroundResourceYV" format="reference" />
<attr name="nextButtonBackgroundResourceYV" format="reference" />

对于三列你需要改变

转到 calendarlib/layout/yearView.xml

这样做...并根据您的响应等做出所有更改。

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="1">

            <com.github.ik024.calendar_lib.custom.MonthView
                android:id="@+id/mv_year_view_jan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.33" />

            <com.github.ik024.calendar_lib.custom.MonthView
                android:id="@+id/mv_year_view_feb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.33" />

            <com.github.ik024.calendar_lib.custom.MonthView
                android:id="@+id/mv_year_view_march"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.33" />
        </LinearLayout>

或三个中的所有其他

关于像IOS一样的安卓年历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39095730/

相关文章:

ios - 捏合缩放 UIImage

iphone - 单击表格 View 单元格时加载缓慢

android - 将 kSoap 连接到 Spyne 时出错 The attribute '{http://schemas.xmlsoap.org/soap/encoding/}root' is not allowed

java - 新空白 Activity 出​​现空指针异常错误

ios - swift 无法转换类型的值

iphone - 重要位置更改回调的后台时间

iphone - 如何处理 ios 连接丢失

java - 如何从 Firebase 获取数组列表对象

android - 更改 PopupMenu 中单个项目的文本颜色

ios - 带有波浪形(波浪形)顶部的 CustomView。(Swift)