본문 바로가기

안드로이드/팁

[Android] EditText auto focus, auto 키패드 ON/OFF

300x250

ON

EditText의 자동 포커스, 자동 키패드 기능을 적용하려면 EditText의 nextFocusDown 속성을 이용해서 포커스의 순서를 정할 수 있다.

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            <EditText
                    android:id="@+id/search_editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:nextFocusDown="@+id/다음 포커스를 줄 대상의 id"
                    android:inputType="text"/>
</LinearLayout>

또한 자동 키패드를 설정하기 위해서는 AndroidManifest.xml의 해당 Activity에 windowSoftInputMode 속성값을 stateVisible값을 준다.

<activity android:name=".@@@Activity"
                  android:windowSoftInputMode="stateVisible"
                  android:theme="@style/AppTheme"/>

 

 


OFF

반대로, 자동 포커스 기능을 막으려면 EditText를 감싸는 상위 view에 focusable, focusableInTouchMode 속성값에 true를 주어서 상위 view에 focus를 주면 된다.

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="horizontal">

            <EditText
                    android:id="@+id/search_editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text"/>
</LinearLayout>

 

또한 EditText의 자동 키패드를 실행을 막으려면 AndroidManifest.xml의 해당 Activity에 windowSoftInputMode 속성값을 stateAlwaysHidden 값을 준다.

<activity android:name=".@@@Activity"
                  android:windowSoftInputMode="stateAlwaysHidden"
                  android:theme="@style/AppTheme"/>

 

320x100