• 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();
        }
    
    }

    由于代码太多,完整代码未给出,源码直接下载即可

    源码点击下载

  • 相关阅读:
    取消select默认样式
    浏览器私有前缀
    兼容ie的background-size: cover;
    关于字体
    lorem 快速生成x个单词
    bash常见命令
    rgba透明的兼容处理
    JDK源码分析(10) CopyOnWriteArrayList
    JDK源码分析(9) LinkedHashMap
    JDK源码分析(8) StringBuffer & StringBuilder
  • 原文地址:https://www.cnblogs.com/zhangqie/p/6372918.html
Copyright © 2020-2023  润新知