-
Notifications
You must be signed in to change notification settings - Fork 1
CustomSwitchView
jimbo edited this page May 29, 2026
·
1 revision
- ๊ฐ๋จํ ์์ฑ๊ฐ์ผ๋ก Apple(iOS) ์คํ์ผ์ ํ ๊ธ ์ค์์น๋ฅผ ๊ตฌํํ ์ ์๋ ViewClass ์
๋๋ค.
(A toggle switch View that replicates the iOS UISwitch style using simple attribute values.)
| Attribute | Type | Description |
|---|---|---|
| switchChecked | Boolean | Sets the initial checked state of the switch. |
| switchTrackColorOn | Color | Track color when the switch is ON. |
| switchTrackColorOff | Color | Track color when the switch is OFF. |
| switchThumbColor | Color | Color of the thumb (circle). |
| switchThumbSize | Dimension | Diameter of the thumb. If not set, auto-calculated from track height. |
| switchThumbMargin | Dimension | Margin between the thumb and the track edge. Default is 2dp. |
| switchAnimDuration | Integer | Duration of the toggle animation in milliseconds. Default is 250ms. |
| switchTouchPadding | Dimension | Expands the touch area via TouchDelegate without changing the visual size. |
-
switchTouchPadding์ ๋ถ๋ชจ View ์TouchDelegate๋ฅผ ์ค์ ํ๋ ๋ฐฉ์์ผ๋ก ๋์ํฉ๋๋ค.
๋ถ๋ชจ View ๊ฐ ์ด๋ฏธTouchDelegate๋ฅผ ์ฌ์ฉํ๊ณ ์๋ ๊ฒฝ์ฐ ๋ฎ์ด์ฐ๊ธฐ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
(switchTouchPadding works by setting a TouchDelegate on the parent View. If the parent already uses a TouchDelegate, it may be overwritten.) -
switchThumbSize๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด track ๋์ด ๊ธฐ์ค์ผ๋ก thumb ํฌ๊ธฐ๊ฐ ์๋ ๊ณ์ฐ๋ฉ๋๋ค.
(If switchThumbSize is not set, the thumb size is automatically calculated based on the track height.)
- xml
<hmju.widget.view.CustomSwitchView
android:id="@+id/vSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:switchChecked="false"
app:switchTrackColorOn="#00A18E"
app:switchTrackColorOff="#8E9292"
app:switchThumbColor="#FFFFFF"
app:switchThumbSize="12dp"
app:switchThumbMargin="4dp"
app:switchAnimDuration="400"
app:switchTouchPadding="16dp" />- kotlin
// ์ํ ๋ณ๊ฒฝ ์ฝ๋ฐฑ
vSwitch.setOnCheckedChangeListener { isChecked ->
if (isChecked) {
// ON ์ฒ๋ฆฌ
} else {
// OFF ์ฒ๋ฆฌ
}
}
// ์ฝ๋์์ ์ํ ๋ณ๊ฒฝ
vSwitch.isChecked = trueimplementation 'com.github.sieunju.widget:view:$latestVersion'