电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

Android自定義日歷效果

瀏覽:57日期:2022-09-24 09:32:25

因為工作功能需求,自定義一個日歷,效果如下,點擊選中日歷

Android自定義日歷效果

使用github上面一個前輩的框架

implementation ’com.necer.ncalendar:ncalendar:5.0.0’implementation ’com.github.CodingEnding:PopupLayout:v1.0’//poplayout

框架使用基本類型地址,大家可以根據需要學習修改:地址

自定義日歷的xml文件

<?xml version='1.0' encoding='utf-8'?><androidx.constraintlayout.widget.ConstraintLayout 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:layout_width='match_parent' android:layout_height='wrap_content' tools:context='.CalendarActivity'> <View android: android:layout_width='320dp' android:layout_height='40dp' android:background='@drawable/calendar_bg' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginStart='18dp' android:text='2018' android:textColor='#ffffff' android:textSize='16sp' app:layout_constraintBottom_toBottomOf='@id/title_bar' app:layout_constraintStart_toStartOf='@id/title_bar' app:layout_constraintTop_toTopOf='@id/title_bar' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginStart='18dp' android:text='四' android:textColor='#ffffff' android:textSize='18sp' app:layout_constraintBottom_toBottomOf='@id/title_bar' app:layout_constraintEnd_toEndOf='@id/title_bar' app:layout_constraintStart_toStartOf='@id/title_bar' app:layout_constraintTop_toTopOf='@id/title_bar' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='月' android:textColor='#ffffff' android:textSize='18sp' app:layout_constraintBottom_toBottomOf='@id/title_bar' app:layout_constraintStart_toEndOf='@id/month' app:layout_constraintTop_toTopOf='@id/title_bar' /> <com.necer.view.WeekBar android: android:layout_width='320dp' android:layout_height='wrap_content' android:layout_marginTop='10dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toBottomOf='@id/title_bar' /> <com.necer.calendar.MonthCalendar android: android:layout_width='320dp' android:layout_height='280dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toBottomOf='@id/week' /> <View android: android:layout_width='320dp' android:layout_height='40dp' android:background='@drawable/calendar_bg_bottom' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toBottomOf='@id/month_calendar' /> <TextView android: android:layout_width='0dp' android:layout_height='wrap_content' android:gravity='center' android:onClick='lastYear' android:text='上一年' android:textColor='#ffffff' app:layout_constraintBottom_toBottomOf='@id/bottom_view' app:layout_constraintEnd_toStartOf='@id/dividerOne' app:layout_constraintStart_toStartOf='@id/bottom_view' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <View android: android:layout_width='1dp' android:layout_height='40dp' android:background='#ffffff' app:layout_constraintEnd_toStartOf='@id/lastMonth' app:layout_constraintStart_toEndOf='@id/lastYear' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <TextView android: android:layout_width='0dp' android:layout_height='wrap_content' android:gravity='center' android:onClick='lastMonth' android:text='上個月' android:textColor='#ffffff' app:layout_constraintBottom_toBottomOf='@id/bottom_view' app:layout_constraintEnd_toStartOf='@id/dividerTwo' app:layout_constraintStart_toEndOf='@id/dividerOne' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <View android: android:layout_width='1dp' android:layout_height='40dp' android:background='#ffffff' app:layout_constraintEnd_toStartOf='@id/nextMonth' app:layout_constraintStart_toEndOf='@id/lastMonth' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <TextView android: android:layout_width='0dp' android:layout_height='wrap_content' android:gravity='center' android:text='下個月' android:textColor='#ffffff' android:onClick='nextMonth' app:layout_constraintBottom_toBottomOf='@id/bottom_view' app:layout_constraintEnd_toStartOf='@id/dividerThree' app:layout_constraintStart_toEndOf='@id/dividerTwo' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <View android: android:layout_width='1dp' android:layout_height='40dp' android:background='#ffffff' app:layout_constraintEnd_toStartOf='@id/nextYear' app:layout_constraintStart_toEndOf='@id/nextMonth' app:layout_constraintTop_toTopOf='@id/bottom_view' /> <TextView android: android:layout_width='0dp' android:layout_height='wrap_content' android:gravity='center' android:text='下一年' android:textColor='#ffffff' android:onClick='nextYear' app:layout_constraintBottom_toBottomOf='@id/bottom_view' app:layout_constraintEnd_toEndOf='@id/bottom_view' app:layout_constraintStart_toEndOf='@id/dividerThree' app:layout_constraintTop_toTopOf='@id/bottom_view' /></androidx.constraintlayout.widget.ConstraintLayout>

MainActivity,日歷的功能重寫也是在和這個函數中

package com.example.calendartest;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.os.Handler;import android.view.View;import android.widget.Button;import android.widget.TextView;import com.codingending.popuplayout.PopupLayout;import com.necer.calendar.BaseCalendar;import com.necer.calendar.MonthCalendar;import com.necer.enumeration.CheckModel;import com.necer.enumeration.DateChangeBehavior;import com.necer.listener.OnCalendarChangedListener;import org.joda.time.LocalDate;public class MainActivity extends AppCompatActivity { PopupLayout popupLayout; View calendarView; TextView mYear, mMonth, lastYear, nextYear, lastMonth, nextMonth; MonthCalendar monthCalendar; int currentYear, currentMonth; Button intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent = findViewById(R.id.intent); calendarView = View.inflate(this, R.layout.calendar, null); popupLayout = PopupLayout.init(this, calendarView); } public void intent(View view) { initCalendar(); popupLayout.show(PopupLayout.POSITION_CENTER); } public void initCalendar() { monthCalendar = calendarView.findViewById(R.id.month_calendar); mYear = calendarView.findViewById(R.id.year); mMonth = calendarView.findViewById(R.id.month); lastYear = calendarView.findViewById(R.id.lastYear); nextYear = calendarView.findViewById(R.id.nextYear); lastMonth = calendarView.findViewById(R.id.lastMonth); nextMonth = calendarView.findViewById(R.id.nextMonth); monthCalendar.setCheckMode(CheckModel.SINGLE_DEFAULT_UNCHECKED); monthCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { mYear.setText(String.valueOf(year)); mMonth.setText(String.valueOf(month)); intent.setText(String.valueOf(localDate)); currentYear = year; currentMonth = month; new Handler().postDelayed(new Runnable() { @Override public void run() { popupLayout.dismiss(); } },800); } }); } public void lastMonth(View view) { monthCalendar.toLastPager(); } public void nextMonth(View view) { monthCalendar.toNextPager(); } public void nextYear(View view) { monthCalendar.jumpDate(currentYear + 1, currentMonth, 1); } public void lastYear(View view) { monthCalendar.jumpDate(currentYear - 1, currentMonth, 1); }}

GitHub下載地址

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 济南菜鸟驿站广告|青岛快递车车体|社区媒体-抖音|墙体广告-山东揽胜广告传媒有限公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 陶氏道康宁消泡剂_瓦克消泡剂_蓝星_海明斯德谦_广百进口消泡剂 | 挤出机_橡胶挤出机_塑料挤出机_胶片冷却机-河北伟源橡塑设备有限公司 | 仿古瓦,仿古金属瓦,铝瓦,铜瓦,铝合金瓦-西安东申景观艺术工程有限公司 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 铁盒_铁罐_马口铁盒_马口铁罐_铁盒生产厂家-广州博新制罐 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 聚合甘油__盐城市飞龙油脂有限公司 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 叉车电池-叉车电瓶-叉车蓄电池-铅酸蓄电池-电动叉车蓄电池生产厂家 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 洗砂机械-球磨制砂机-洗沙制砂机械设备_青州冠诚重工机械有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 铜镍-康铜-锰铜-电阻合金-NC003 - 杭州兴宇合金有限公司 | 展厅装修公司|企业展厅设计|展厅制作|展厅搭建—广州展厅装饰公司 | 北京租车牌|京牌指标租赁|小客车指标出租 | 湖南自考_湖南自学考试 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | HV全空气系统_杭州暖通公司—杭州斯培尔冷暖设备有限公司 | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 超声波成孔成槽质量检测仪-压浆机-桥梁预应力智能张拉设备-上海硕冠检测设备有限公司 | 地图标注|微信高德百度地图标注|地图标记-做地图[ZuoMap.com] | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 重庆小面培训_重庆小面技术培训学习班哪家好【终身免费复学】 | 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 泰国试管婴儿_泰国第三代试管婴儿_泰国试管婴儿费用/多少钱_孕泰来 | PC构件-PC预制构件-构件设计-建筑预制构件-PC构件厂-锦萧新材料科技(浙江)股份有限公司 | elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 自进式锚杆-自钻式中空注浆锚杆-洛阳恒诺锚固锚杆生产厂家 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 泰国试管婴儿_泰国第三代试管婴儿费用|成功率|医院—新生代海外医疗 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 无轨电动平车_轨道平车_蓄电池电动平车★尽在新乡百特智能转运设备有限公司 | 河北码上网络科技|邯郸小程序开发|邯郸微信开发|邯郸网站建设 |