Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等
Posted 切切歆语
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 之日历控件,可左右滑动,包含公历,农历,节假日等的主要内容,如果未能解决你的问题,请参考以下文章
WPF 自定义BarChartControl(可左右滑动的柱状图)(转)