首页 > 其他分享 >安卓开发日历(带农历日期、节气)

安卓开发日历(带农历日期、节气)

时间:2024-10-09 09:18:11浏览次数:3  
标签:calendarView CalendarView 安卓 日历 节气 cDate title void TextView

效果图在最底下

一、java类: 

public class Calendar extends AppCompatActivity {

    private CalendarView calendarView;

    private int[] cDate = CalendarUtil.getCurrentDate();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calendar);
        final TextView title = (TextView) findViewById(R.id.title);
        //当前选中的日期
        calendarView = (CalendarView) findViewById(R.id.calendar);


        View calendarContent = findViewById(R.id.calendar); // 获取 CalendarView
        if (calendarContent instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) calendarContent;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                View child = viewGroup.getChildAt(i);
                if (child instanceof TextView) {
                    ((TextView) child).setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
                }
            }
        }
        calendarView
                .setStartEndDate("1949.1", "2050.12")
                .setDisableStartEndDate("1949.10.10", "2050.10.10")
                .setInitDate(cDate[0] + "." + cDate[1])
                .setSingleDate(cDate[0] + "." + cDate[1] + "." + cDate[2])
                .init();

        title.setText(cDate[0] + "年" + cDate[1] + "月");

        calendarView.setOnPagerChangeListener(new OnPagerChangeListener() {
            @Override
            public void onPagerChanged(int[] date) {
                title.setText(date[0] + "年" + date[1] + "月");
            }
        });

    }

    public void lastMonth(View view) {
        calendarView.lastMonth();
    }  // 上一月

    public void nextMonth(View view) {
        calendarView.nextMonth();
    }  // 下一月


}

二、xml部分

<RelativeLayout 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/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".function.calendar.Calendar">


    <LinearLayout
        android:id="@+id/leftLayout"
        android:layout_width="500dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#729EF4"
        android:padding="20dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true">


    <LinearLayout
        xmlns:calendarview="http://schemas.android.com/apk/res-auto"
        android:layout_width="800dp"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:layout_marginLeft="500dp"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="800dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@mipmap/last"
                android:layout_marginLeft="20dp"
                android:onClick="lastMonth" />

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="30sp"
                android:textStyle="bold" />

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="50dp"
                android:background="@mipmap/next"
                android:onClick="nextMonth" />

        </RelativeLayout>

        <com.othershe.calendarview.weiget.WeekView
            android:layout_width="800dp"
            android:layout_height="35dp"
            android:layout_marginTop="30dp"
            android:scrollbarSize="20dp"/>

        <com.othershe.calendarview.weiget.CalendarView
            android:id="@+id/calendar"
            android:layout_width="700dp"
            android:layout_height="match_parent"
            calendarview:choose_type="single"
            calendarview:show_holiday="true"
            calendarview:show_lunar="true"
            calendarview:show_term="true"
            android:layout_marginTop="25dp"
            calendarview:switch_choose="false"
            android:layout_marginLeft="35dp"
            calendarview:lunar_size="15"
            calendarview:solar_size="30"/>
    </LinearLayout>


</RelativeLayout>

三、主要依赖部分

implementation 'com.github.Othershe:CalendarView:calendarview'
implementation 'cn.6tail:lunar:sun'
implementation 'com.github.Othershe:CalendarView:calendarview'

标签:calendarView,CalendarView,安卓,日历,节气,cDate,title,void,TextView
From: https://blog.csdn.net/qq_65679572/article/details/142753144

相关文章

  • 红队老子养成记2 - 不想渗透pc?我们来远控安卓!(全网最详细)
    大家好,我是Dest1ny。今天我们是红队专题中的远控安卓。这个实验会非常有趣,大家多多点赞!环境:一台有公网ip的vps/kali/带msf工具即可一台安卓手机(最好老一点,因为我们这里不涉及免杀)CLASS-1msfconsole和msfvenommsfconsole功能:msfconsole是Metasploit框架......
  • 【一句日历】2024年10月
    【2023年10月1日·星期二】大雨落幽燕,白浪滔天。秦皇岛外打鱼船。一片汪洋都不见,知向谁边?往事越千年,魏武挥鞭,东临碣石有遗篇。萧瑟秋风今又是,换了人间。                                       ......
  • VBA日历进度
    hi,大家好!经过两次台风的洗礼之后,我们这里终于开始降温了,终于感觉到秋天的存在了!时间也在一天天的过去,马上要十一假期了,十一过了,就可以算着过年了,让今天就让我们来算算,离年底还剩余多少?(文章编辑时间为2024-09-23)那我们就来看看怎么做吧!01、创建窗体这里我们先来创建一个窗体,在窗体上......
  • 安卓Android虚拟机分享及使用
    不知道大家伙在安装安卓虚拟机时被各式各样的问题折磨过没,我在安装安卓虚拟机时,遇到的问题简直就像长江之水源源不断,就算是最后安装好了也会因为各式各样的原因无法进入启动桌面。当我发现这个可以直接导入到电脑一键开启运行的虚拟机时,今天我必须分享给大家!话不多说安排!这个可......
  • WPS Office安卓版(WPS Office国际版) v18.13 解锁高级版
    WPSOfficeforAndroid是一款功能强大的安卓手机办公软件。 软件功能1.支持多种办公文档,包括Word、Excel和PowerPoint等。2.多种视图模式,支持纯文本、Web视图、页面视图、阅读视图等不同视图。3.支持多种文档操作,如文档的新建、编辑、保存、打印、分享、拍照OCR等。4.内置云......
  • 基于php的女大学生卡路里跟踪与分析系统小程序app安卓设计(源码+文档+部署讲解等)
    前言......
  • 【Ehviewer绿色版】2.0.8.4最新版本下载2024安卓苹果
    Ehviewer开发应用程序(App)是一项综合性的工作,涉及从构思到发布等多个环节。以下是开发一个基本应用程序的教程,Ehviewer包括从概念设计到发布的完整流程。Ehviewer本教程将分别介绍iOS和Android平台的开发过程。ehviewer官方安装包下载:http://ez.oubaidu.com/一、Ehviewer构......
  • ehviewer绿色版1.9.5.2最新2024ios苹果安卓
    随着科技的不断发展,手机已经成为我们生活中不可或缺的一部分。在这个数字化时代,人们对于娱乐方式的需求也在逐渐改变。其中,漫画作为一种受欢迎的阅读形式,已经从传统的纸质书籍转变为数字版。而今天,我要为大家介绍的这款软件——ehviewer绿色版1.9.5.2,正是为了满足广大漫画爱好者的......
  • Qt/C++ 音视频开发 - FFmpeg 安卓版
    Qt/C++音视频开发-FFmpeg安卓版介绍FFmpeg是一个开源的多媒体框架,它可以用来录制、转换和流式传输音视频。在Qt/C++开发中,FFmpeg可以用于处理各种音视频任务,例如转码、推流等。将FFmpeg集成到安卓平台上,可以实现强大的移动端音视频处理功能。应用使用场景视频......
  • ehviewer绿色版2.0.2.4最新版本安卓苹果下载安装
    制作应用程序(App)ehviewer是一项涉及多个步骤和技术的任务,ehviewer可以从零开始创建一个简单的应用,ehviewer也可以扩展到复杂的多功能应用。以下是制作一个基本应用程序的教程,以Android平台为例进行说明。ehviewer本教程将涵盖从构思到发布应用的ehviewer整个过程。ehviewer绿色......