반응형
커스터마이징한 EditText가 필요해서 아래와 같이 코드를 작성하였는데
컴파일 에러나 런타임 에러는 없는데, 이상하게 원하는데로 동작하지가 않았다.
class MyEditText @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : AppCompatEditText(context!!, attrs, defStyle)
알고 보니 생성자를 아래와 같이 선언해야 한다.
class MyEditText : AppCompatEditText(context!!, attrs, defStyle) {
constructor(context: Context?) : super(context!!) {}
constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {}
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context!!, attrs, defStyle) {}
}
이유는 TextView와 EditText의 생성자에서 defStyle을 자체 기본 값으로 덮어쓰기 때문이다.
반응형
'개발 > Android' 카테고리의 다른 글
[compose] TextField로 숫자 입력 시 VisualTransformation 사용하여 쉼표(,) 붙여주기 (0) | 2023.04.16 |
---|---|
Android 코드로 Dark 모드 on/off (0) | 2020.12.16 |
RecyclerView의 특정 아이템 위치로 이동하기 (0) | 2020.11.08 |
Bitbucket Pipeline으로 Android APK 빌드하기 (0) | 2020.11.08 |
[Android Dev Summit ’19] What’s New in Room – 정리 (0) | 2020.11.08 |