본문 바로가기

Android

[Android] Focus

뷰와 사용자가 상호 작용을 하기 시작할 때 그 뷰는 Focus를 가졌다고 합니다.

 

간단한 예시로

EditText가 있으며 EditText를 터치하면 키보드가 나타나면서 EditText와 상호 작용을 할 수 있게 되는데

이때 EditText는 Focus를 가지게 됩니다.

 

Focus를 갖기 위해 Focusable의 속성이 true가 되어야 하는데, EditText의 경우 별도의 작업 없이 

true값을 갖지만 TextView와 같은 태그들은 임의로 속성값을 바꾸어 주어야 합니다.

 

ex) 

xml에서 해당 태그에

android:focusable="true"
android:focusableInTouchMode="true"

를 추가해 주거나

findViewById<Button>(R.id.button).requestFocus()

kt파일에서 requestFocus메서드를 사용하면 됩니다.

'Android' 카테고리의 다른 글

[Android] Layouts  (0) 2021.01.28
[Android] Palette (Helper)  (0) 2021.01.27
[Android] Fragment 생명주기  (0) 2021.01.27
[Android] Palette (Containers)  (0) 2021.01.26