티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How to stop EditText from gaining focus when an activity starts in Android?
Android에서 액티비티가 시작될 때 EditText에 포커스 가는 것 막기
문제 내용
I have an Activity
in Android, with two elements:
Android에는 다음과 같은 두 가지 요소가 포함된 Activity가 있습니다.
EditText
ListView
When my Activity
starts, the EditText
immediately has the input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:
내 액티비티가 시작되면 EditText는 즉시 입력 포커스(커서 깜박임)를 가집니다. 저는 시작할 때 컨트롤에 입력 포커스가 되는 것을 원하지 않습니다. 나는 아래를 시도해봤다:
EditText.setSelected(false);
EditText.setFocusable(false);
No luck. How can I convince the EditText
to not select itself when the Activity
starts?
운이 없다. 액티비티가 시작될 때 EditText가 자동으로 선택되지 않도록 하려면 어떻게 해야 합니까?
높은 점수를 받은 Solution
Adding the tags android:focusableInTouchMode="true"
and android:focusable="true"
to the parent layout (e.g. LinearLayout
or ConstraintLayout
) like in the following example, will fix the problem.
다음 예와 같이 Android:focusableInTouchMode="true" 및 Android:refocusable="true" 태그를 상위 레이아웃(예: LinearLayout 또는 ConstraintLayout)에 추가하면 문제가 해결됩니다.
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="@id/autotext"
android:nextFocusLeft="@id/autotext"/>
가장 최근 달린 Solution
Simply add android:focusableInTouchMode="true"
in the parent layout of EditText and you will get rid of this awkward behavior.
Android:focusableInTouchMode="true"를 EditText의 상위 레이아웃에 추가하기만 하면 이러한 어색한 동작을 없앨 수 있습니다.
출처 : https://stackoverflow.com/questions/1555109/how-to-stop-edittext-from-gaining-focus-when-an-activity-starts-in-android
'개발 > 안드로이드' 카테고리의 다른 글
android.os.FileUriExposedException 수정하는 방법 (0) | 2022.11.30 |
---|---|
intent를 사용하여 다른 액티비티로 object를 보내는 방법 (0) | 2022.11.30 |
onActivityResult가 Fragment에서 호출되지 않습니다 (0) | 2022.11.30 |
WebView에서 뒤로 버튼을 눌렀을 때 이전 페이지로 돌아가는 방법 (0) | 2022.11.29 |
안드로이드 인텐스에서 추가 데이터를 얻으려면 어떻게 해야 하나요? (0) | 2022.11.29 |