色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Android自定義日歷效果

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

因?yàn)楣ぷ鞴δ苄枨螅远x一個(gè)日歷,效果如下,點(diǎn)擊選中日歷

Android自定義日歷效果

使用github上面一個(gè)前輩的框架

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

框架使用基本類型地址,大家可以根據(jù)需要學(xué)習(xí)修改:地址

自定義日歷的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='上個(gè)月' 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='下個(gè)月' 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,日歷的功能重寫也是在和這個(gè)函數(shù)中

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下載地址

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 欧美精品一二三区 | 国产精品免费精品自在线观看 | 欧美日韩一区二区不卡三区 | a级国产乱理伦片在线 | 色老头久久网 | 久久在线 | 亚洲综合图片人成综合网 | 成年人精品视频 | 欧美一区二区三区在观看 | 亚洲国产成人精品激情 | 亚洲国产精品不卡毛片a在线 | 深夜国产成人福利在线观看女同 | 91精品久久久久久久久网影视 | 亚洲欧美一区二区三区久本道 | 欧美白人和黑人xxxx猛交视频 | 久久亚洲欧洲日产国码 | 久久亚洲国产 | 国产情侣久久 | 久久精品国产精品青草不卡 | 老师张开腿让我爽了一夜视频 | 六月丁香久久丫 | 亚洲无限看 | 久久久免费精品 | 亚洲va中文字幕 | 黄a免费| 一级欧美激情毛片 | 久久久久久国产精品视频 | 国产成人久久精品一区二区三区 | 女人张开腿让男人 | 91欧美一区二区三区综合在线 | 国产亚洲欧美在线播放网站 | 国产人成 | 欧美黄色免费 | 国产一区二区三区不卡在线观看 | 国产亚洲精品aaa大片 | 加勒比色综合久久久久久久久 | 国产精品自在线天天看片 | 国产90后美女露脸在线观看 | 国内真实愉拍系列情侣自拍 | 欧美精品三区 | 欧美成人久久一级c片免费 欧美成人看片黄a免费 |