首页 > 代码库 > Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等
Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等
公司项目需要日历这个功能,经过查阅资料写了个demo,包含公历,农历,节假日等,还可左右滑动。
效果图:
代码:
public class MainActivity extends AppCompatActivity implements CalendarViewPagerFragment.OnPageChangeListener, CalendarViewFragment.OnDateClickListener, CalendarViewFragment.OnDateCancelListener { private TextView tv_date; private List<CalendarDate> mListDate = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_date = (TextView) findViewById(R.id.tv_date); initFragment(); } private void initFragment() { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); Fragment fragment = CalendarViewPagerFragment.newInstance(); tx.replace(R.id.fl_content, fragment); tx.commit(); } @Override public void onDateClick(CalendarDate calendarDate) { int year = calendarDate.getSolar().solarYear; int month = calendarDate.getSolar().solarMonth; int day = calendarDate.getSolar().solarDay; String data; if (day < 10) { data = DateUtils.getWeekday(year + "-" + month + "-0" + day); tv_date.setText(year + "-" + month + "-0" + day + " " + month + "月" + " " + data); } else { data = DateUtils.getWeekday(year + "-" + month + "-" + day); tv_date.setText(year + "-" + month + "-" + day + " " + month + "月" + " " + data); } } @Override public void onDateCancel(CalendarDate calendarDate) { } @Override public void onPageChange(int year, int month) { tv_date.setText(year + "-" + month); mListDate.clear(); } }
由于代码太多,完整代码未给出,源码直接下载即可
源码点击下载
Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。