티스토리 뷰

Android/UI

CalendarView

parkho79 2019. 8. 27. 10:04
728x90



 

CalendarView 는 스크롤이 가능한 달력을 보여준다.

탭, 클릭 이벤트로 날짜를 선택 할 수 있으며 원하는 날짜로 달력을 스크롤 하고 찾을 수 있다.



How to

◼ CalendarView code in XML

<CalendarView
android:id="@+id/simple_calendarview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
view raw layout.xml hosted with ❤ by GitHub

 

◼ CalendarView code in JAVA

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
long selectedDate = calendarView.getDate();
view raw main.java hosted with ❤ by GitHub



Attributes

◼ id

id 는 해당 CalendarView 를 유일하게 식별할 수 있는 속성이다.

<CalendarView
android:id="@+id/simple_calendarview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
view raw layout.xml hosted with ❤ by GitHub



◼ firstDayOfWeek

요일의 시작을 어떤 요일로 할지 설정.

- 1 : 일요일 (default)

- 2 : 월요일

<CalendarView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:firstDayOfWeek="2" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ focusedMonthDateColor

현재 선택된 달의 배경색

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

 

◼ unfocusedMonthDateColor

선택되지 않은 달의 배경색

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

 

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusedMonthDateColor="#00FF00"
android:unfocusedMonthDateColor="#FF0000" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ maxDate

달력에 표시할 최대 날짜 설정

- mm/dd/yyyy 형식으로 지정 (default : 01/01/2100)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxDate="05/22/2019" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ minDate

달력에 표시할 최소 날짜 설정

- mm/dd/yyyy 형식으로 지정 (default : 01/01/1900)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minDate="05/22/2019" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ selectedDateVericalBar

선택한 날짜의 양쪽에 보일 수직바 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:selectedDateVerticalBar="@android:color/black" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ selectedWeekBackgrounColor

선택된 주의 배경색상 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:selectedWeekBackgroundColor="#0000FF" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ showWeekNumber

왼쪽에 주차를 보여줄 것인지 설정 (default = true)

해당 API 는 API level 24 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:showWeekNumber="false" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ weekNumberColor

주차의 색상지정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weekNumberColor="#FF0000" />
view raw layout.xml hosted with ❤ by GitHub

 



◼ weekSeparatorLineColor

주 구분선 색상 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weekSeparatorLineColor="#FF0000" />
view raw layout.xml hosted with ❤ by GitHub

 



Methods

◼ getDate()

현재 선택된 날짜를 millisecond 단위로 반환

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
long selectedDate = calendarView.getDate();
view raw main.java hosted with ❤ by GitHub



◼ setDate(long date)

Millisecond 단위로 날짜 선택

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setDate(1570668133353L);
view raw main.java hosted with ❤ by GitHub



◼ setFirstDayOfWeek(int firstDayOfWeek)

요일의 시작을 어떤 요일로 할지 설정.

- 1 : 일요일 (default)

- 2 : 월요일

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setFirstDayOfWeek(2);
view raw main.java hosted with ❤ by GitHub



◼ getFirstDayOfWeek()

요일의 시작일 반환

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int firstDayOfWeek = calendarView.getFirstDayOfWeek();
view raw main.java hosted with ❤ by GitHub



◼ setMaxDate(long maxDate)

달력에 표시할 최대 날짜 설정

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setMaxDate(1558483200000L); // '05/22/2019'
view raw main.java hosted with ❤ by GitHub



◼ getMaxDate()

달력에 설정된 최대 날짜 반환

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
long maxDate = calendarView.getMaxDate();
view raw main.java hosted with ❤ by GitHub



◼ setMinDate(long minDate)

달력에 표시할 최소 날짜 설정

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setMinDate(1558483200000L); // '05/22/2019'
view raw main.java hosted with ❤ by GitHub



◼ getMinDate()

달력에 설정된 최소 날짜 반환

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
long minDate = calendarView.getMinDate();
view raw main.java hosted with ❤ by GitHub



◼ setShowWeekNumber(boolean showWeekNumber)

왼쪽에 주차를 보여줄 것인지 설정 (default = true)

해당 API 는 API level 24 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setShowWeekNumber(false);
view raw main.java hosted with ❤ by GitHub



◼ getShowWeekNumber()

왼쪽에 주차가 보여지는지 확인

해당 API 는 API level 24 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
boolean isShow = calendarView.getShowWeekNumber();
view raw main.java hosted with ❤ by GitHub



◼ getSelectedDateVerticalBar()

수직바에 설정된 drawable 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
Drawable verticalBar = calendarView.getSelectedDateVerticalBar();
view raw main.java hosted with ❤ by GitHub



◼ setSelectedDateVerticalBar(Drawabledrawable) or (int resourceId)

선택한 날짜의 양쪽에 보일 수직바 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setSelectedDateVerticalBar(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ setSelectedWeekBackgroundColor(int color)

선택된 주의 배경색상 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setSelectedWeekBackgroundColor(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ getSelectedWeekBackgroundColor()

선택된 주의 배경색상 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int color = calendarView.getSelectedWeekBackgroundColor();
view raw main.java hosted with ❤ by GitHub



◼ setWeekNumberColor(int color)

주차의 색상 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setWeekNumberColor(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ getWeekNumberColor()

설정된 주차의 색상 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int color = calendarView.getWeekNumberColor();
view raw main.java hosted with ❤ by GitHub



◼ setWeekSeparatorLineColor(int color)

주 구분선 색상 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setWeekSeparatorLineColor(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ getWeekSeparatorLineColor()

주 구분선 색상 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int color = calendarView.getWeekSeparatorLineColor();
view raw main.java hosted with ❤ by GitHub



◼ setFocusedMonthDateColor(int color)

선택된 달의 배경색 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setFocusedMonthDateColor(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ getFocusedMonthDateColor()

선택된 달의 배경색 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int color = calendarView.getFocusedMonthDateColor();
view raw main.java hosted with ❤ by GitHub



◼ setUnfocusedMonthDateColor(int color)

선택되지 않은 달의 배경색 설정

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setUnfocusedMonthDateColor(Color.BLACK);
view raw main.java hosted with ❤ by GitHub



◼ getUnfocusedMonthDateColor()

선택되지 않은 달의 배경색 반환

해당 API 는 API level 23 까지만 지원한다. (Material style 에서는 지원되지 않는다.)

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
int color = calendarView.getUnfocusedMonthDateColor();
view raw main.java hosted with ❤ by GitHub



◼ setOnDateChangeListener(OnDateChangeListenerlistener)

날짜를 선택하여 변경하게 되면 호출되는 listener

CalendarView calendarView = (CalendarView) findViewById(R.id.simple_calendarview);
calendarView.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
Toast.makeText(PhSecondActivity.this, year + "/" + month + "/" + dayOfMonth, Toast.LENGTH_SHORT).show();
}
});
view raw main.java hosted with ❤ by GitHub



728x90

'Android > UI' 카테고리의 다른 글

Scrollview & HorizontalScrollView  (0) 2019.08.27
SearchView  (0) 2019.08.27
MultiAutoCompleteTextView  (0) 2019.08.27
AutoCompleteTextView  (0) 2019.08.27
TextClock  (0) 2019.08.27
댓글