Android
[Kotlin] EditText의 엔터(<┘)를 완료로 바꾸기 + EditText에 내용이 없을 때 버튼을 못누르게 하기
dev210202
2020. 5. 19. 16:11
EditText의 엔터를 바꾸는 방법은 다음과 같다.
1. xml파일에서 해당하는 EditText에 다음과 같이 추가한다
android:imeOptions="actionDone"
EditText에 내용이 없을 때 버튼을 못누르게 하는 방법은 다음과 같다.
1. EditText에 addTextChangedListener를 달아준다.
2. onTextChanged 함수에 if문으로 EditText에 내용이 있는지 확인해서 버튼을 사용할 수 없게 만든다.
내가 짠 코드는 다음과같다.(DataBinding 사용)
binding.linkinput.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (linkinput.text.toString() == "") {
completeButton.isEnabled = false
completeButton.setBackgroundResource(R.drawable.createchat_complete_button_false_style)
} else if (linkinput.text.toString() != "") {
completeButton.isEnabled = true
completeButton.setBackgroundResource(R.drawable.createchat_complete_button_true_style)
}
}
})