1. EditText 활성화 시 밑줄 색상 변경
![]() |
![]() |
EditText 비활성화 | EditText 활성화 |
- res > values > style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">@color/gray</item>
//비활성화 컬러 지정
<item name="colorControlActivated">@color/malibu</item>
//활성화 컬러 지정
</style>
</resources>
- 적용할 .xml > EditText 속성 값 설정
<EditText
...
style="@style/EditTextStyle"
app:theme="@style/EditTextStyle"
...
/>
2. EditText 작성 후, Enter 시 키보드 숨기기/포커스 숨기기/완료 처리
![]() |
![]() |
![]() |
EditText 작성 전 | EditText 작성 중 | Enter 후 |
- 완료 처리
- 만약, 엔터 시 검색처리를 하고 싶다면 ? imeOptins = actionSearch 로 변경하여 작성
//xml에 아래의 코드 추가
<EditText
...
android:id="@+id/et_Room_Title"
android:imeOptions="actionDone"
android:inputType="text"
...
/>
//setOnEditorActionListener : actionDone 처리
binding.etRoomTitle.setOnEditorActionListener { textView, action, keyEvent ->
var handled = false
if (action == EditorInfo.IME_ACTION_DONE) {
handled = true
}
handled
}
- 키보드 및 포커스 숨기기
binding.etRoomTitle.setOnEditorActionListener { textView, action, keyEvent ->
var handled = false
if (action == EditorInfo.IME_ACTION_DONE) {//완료하였을 때 처리
hideKeyboard()
//포커스 숨기기
requireActivity().currentFocus!!.clearFocus()
handled = true
}
handled
}
//키보드 숨기기
private fun hideKeyboard() {
val imm =
requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, 0)
}
Pluu Dev - [번역] EditText 색 변경항목 정리
Pluu Dev - [번역] EditText 색 변경항목 정리
[정리] Compose 가이드 문서 ~ 접근성 Posted on 06 Jun 2024 [정리] Compose 가이드 문서 ~ Animation Posted on 06 Jun 2024 [정리] Compose 가이드 문서 ~ Images and graphics Posted on 02 Jun 2024 [요약] What's new in Android development
pluu.github.io
https://velog.io/@seokzoo/EditText에서-사용할-수-있는-유용한-속성
EditText에서 사용할 수 있는 유용한 속성
EditText 기능
velog.io
'Android' 카테고리의 다른 글
Android Studio_ 12. Google Places(New) API 사용하기 (1) | 2024.06.06 |
---|---|
Android Studio_ 11. Mapping 처리 방법 (0) | 2024.06.01 |
Android Studio_ 10. 구글 지도앱 만들기 (0) | 2024.05.30 |
Android Studio_ 0-3. Guideline, Barrier, ViewGroup (0) | 2024.04.30 |
Android Studio_ 9. Figma(피그마)에서 이미지 추출해서 사용하기 (0) | 2024.04.24 |