自定义Android日历视图 [英] Custom Android calendarView

查看:30
本文介绍了自定义Android日历视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以在对话框中使用的 CalendarView,如下所示:

I am looking for a CalendarView that can be used in a dialog something like this:

我计划使用 android.widget.CalendarView 但它可以从 API 级别 11 使用.考虑到仍有很多用户使用 android 2.3.3(但不是主要用户),这是一个问题可以放开那组用户).

I plan to use android.widget.CalendarView but it is available from API level 11. That's an issue considering there are still lot of users, using android 2.3.3 (but not a major one can let go those set of user).

我应该使用这些选项中的哪一个?

Which of these options should I use?

1) 可用的库并相应地使用它们.

1) libraries that are available and use them accordingly.

2) 自定义android.widget.CalendarView?

如果是#2,那么有什么例子吗?

If #2, then are there any examples for it?

推荐答案

您好,请访问所有给定的链接,希望对您有所帮助

Hi visit all given links, hope will help you

  1. Betterpickers:https://github.com/derekbrameyer/android-betterpickers

日历同步:http://www.androiddevelopersolutions.com/2013/05/android-calendar-sync.html

简单日历:http://w2davids.wordpress.com/android-简单日历/

Caldroid:https://github.com/roomorama/Caldroid

DateTimePicker:https://github.com/flavienlaurent/datetimepicker

DateTimePicker: https://github.com/flavienlaurent/datetimepicker

当您访问 Betterpickers 时,有关此项目的有效实现,请参阅 sample/ 文件夹.

When you visit Betterpickers, for a working implementation of this project see the sample/ folder.

实现适当的处理程序回调:

Implement the appropriate Handler callbacks:

public class MyActivity extends Activity implements DatePickerDialogFragment.DatePickerDialogHandler {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    // ...
  }

  @Override
  public void onDialogDateSet(int year, int monthOfYear, int dayOfMonth) {
    // Do something with your date!
  }
}

使用其中一个 Builder 类创建一个带有主题的 PickerDialog:

Use one of the Builder classes to create a PickerDialog with a theme:

DatePickerBuilder dpb = new DatePickerBuilder()
    .setFragmentManager(getSupportFragmentManager())
    .setStyleResId(R.style.BetterPickersDialogFragment);
dpb.show();

另外一个例子,你可以访问 Caldroid 并使用如下:

Also for another example you can visit Caldroid and use as follows:

要在您的活动中嵌入 Caldroid 片段,请使用以下代码:

To embed the Caldroid fragment in your activity, use below code:

CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);

FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar1, caldroidFragment);
t.commit();

这篇关于自定义Android日历视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆