티스토리 뷰

CheckBox 는 선택 or 해제 두 가지 상태를 제공하며 toggle 이 불가능한 on/off 스위치라고 말할 수 있다.
여러가지 옵션 중 하나를 선택하는 경우에 많이 쓰인다.
How to
◼ CheckBox code in XML
<CheckBox | |
android:id="@+id/simple_checkbox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" /> |
◼ CheckBox code in JAVA
CheckBox checkBox = (CheckBox) findViewById(R.id.simple_checkbox); | |
Boolean isChecked = checkBox.isChecked(); |
Attributes
◼ id
id 는 해당 check box 를 유일하게 식별할 수 있는 속성이다.
<CheckBox | |
android:id="@+id/simple_checkbox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> |
◼ text
CheckBox 에 표시할 text 를 설정한다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" /> |

◼ checked
해당 check box 를 선택 or 해제 할 수 있는 속성이다.
값은 "true" or "false" 이며 기본값은 "false" 이다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:checked="true" /> |

◼ gravity
Text 를 정렬할 수 있는 속성이다.
- layout_width, layout_height 이 wrap_content 이면 text 가 정렬될 공간이 없어 정렬이 안된다.
- gravity 를 지정하지 않으면 기본 속성인 left, top 이 적용된다.
[Android/Layout] - TextView gravity (TextView gravity 와 동일하다.)
<CheckBox | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center" | |
android:text="Parkho" /> |

◼ textColor
Text 의 색상을 설정한다.
- “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb” 형태로 지정할 수 있다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textColor="#0000FF" /> |

◼ textSize
Text 의 크기를 설정한다.
- sp(scale independent pixel) or dp(density pixel) 로 설정 할 수 있다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textSize="30.00sp" /> |

◼ textStyle
Text 의 style 을 설정한다.
- "bold"(굵게), "italic"(이태릭), "normal"(기본) 을 설정할 수 있고 "|" 로 2개 이상의 설정을 할 수 있다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textStyle="bold | italic" /> |

◼ background
CheckBox 의 배경색을 설정한다.
- color 값이나 drawable 을 설정할 수 있다.
◼ padding
CheckBox 의 왼쪽, 오른쪽, 위, 아래 padding 을 설정한다.
<CheckBox | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:background="#00FF00" | |
android:padding="15.00dp"/> |

'Android > UI' 카테고리의 다른 글
Button (0) | 2019.07.26 |
---|---|
RadioButton & RadioGroup (0) | 2019.07.22 |
EditText (0) | 2019.07.15 |
TextView gravity (0) | 2019.07.09 |
TextView (0) | 2019.07.02 |
- Total
- Today
- Yesterday
- android intent
- 안드로이드 인텐트
- 무료채굴
- M2E
- Intent
- android flag activity
- p2e
- 채굴앱
- StartService
- task
- bindservice
- android activity flag
- onCreateContextMenu
- 리워드 어플
- Android Service
- 안드로이드 서비스
- onContextItemSelected
- StringUtils
- 앱테크
- mPANDO
- 리워드앱
- 앱테크 추천
- RoomDatabase
- registerForContextMenu
- 무료 채굴
- WEMIX
- BroadcastReceiver
- notifyDataSetChanged
- android task
- task 생성
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |