android

[안드로이드] EditText 자동 포커싱 방지 / 키보드 자동으로 올라오는 현상 방지

boywin1992 2022. 5. 22. 11:06
728x90

root layout 에 아래 두 코드를 삽입하세요.

 

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

 

위 코드는 EditText 에 포커스가 자동으로 가는 것을 방지해 줍니다.

실행하는 뷰에 EditText 가 있다면 해당 EditText 로 포커스가 이동 되는 것은 기본값이기 때문입니다.

EditText 로 포커스가 이동되면 자동으로 키보드가 올라옵니다.

 

아래에 참고하실 전체 코드를 첨부해 놓을게요.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

728x90