How to disable auto-focus from EditText in Android Studio

Usually we have multiple widgets including one or more EditTexts in an Activity or fragment.Every time user opens these Activities the focus automatically goes to the top most edittext and the virtual key board pops up.This hides rest of the UI,  which can be very annoying for the user.   To  disable auto-focus from EditText just add the two lines in your xml top level Layout :

<?xml version = \"1.0\" encoding = \"utf-8\"?>
<RelativeLayout xmlns:android = \"http://schemas.android.com/apk/res/android\"
   xmlns:tools = \"http://schemas.android.com/tools\" android:layout_width=\"match_parent\"
   android:layout_height = \"match_parent\" android:paddingLeft= \"@dimen/activity_horizontal_margin\"
   android:paddingRight = \"@dimen/activity_horizontal_margin\"
   android:paddingTop = \"@dimen/activity_vertical_margin\"
   android:paddingBottom = \"@dimen/activity_vertical_margin\" 
   android:focusableInTouchMode=\"true\"
   android:focusable=\"true\"
   tools:context = \".MainActivity\">
   
   <TextView android:text = \"Login\" android:layout_width=\"wrap_content\"
      android:layout_height = \"wrap_content\"
      android:id = \"@+id/textview\"
      android:textSize = \"35dp\"
      android:layout_alignParentTop = \"true\"
      android:layout_centerHorizontal = \"true\" />
      
   <TextView
      android:layout_width = \"wrap_content\"
      android:layout_height = \"wrap_content\"
      android:text = \"Tutorials point\"
      android:id = \"@+id/textView\"
      android:layout_below = \"@+id/textview\"
      android:layout_centerHorizontal = \"true\"
      android:textColor = \"#ff7aff24\"
      android:textSize = \"35dp\" />
      
   <EditText
      android:layout_width = \"wrap_content\"
      android:layout_height = \"wrap_content\"
      android:id = \"@+id/editText\"
      android:hint = \"Enter Name\"
      android:focusable = \"true\"
      android:textColorHighlight = \"#ff7eff15\"
      android:textColorHint = \"#ffff25e6\"
      android:layout_marginTop = \"46dp\"
      android:layout_below = \"@+id/imageView\"
      android:layout_alignParentLeft = \"true\"
      android:layout_alignParentStart = \"true\"
      android:layout_alignParentRight = \"true\"
      android:layout_alignParentEnd = \"true\" />
      
   <ImageView
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:id=\"@+id/imageView\"
      android:src=\"@drawable/abc\"
      android:layout_below=\"@+id/textView\"
      android:layout_centerHorizontal=\"true\" />
      
   <EditText
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:inputType=\"textPassword\"
      android:ems=\"10\"
      android:id=\"@+id/editText2\"
      android:layout_below=\"@+id/editText\"
      android:layout_alignParentLeft=\"true\"
      android:layout_alignParentStart=\"true\"
      android:layout_alignRight=\"@+id/editText\"
      android:layout_alignEnd=\"@+id/editText\"
      android:textColorHint=\"#ffff299f\"
      android:hint=\"Password\" />
      
   <TextView
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:text=\"Attempts Left:\"
      android:id=\"@+id/textView2\"
      android:layout_below=\"@+id/editText2\"
      android:layout_alignParentLeft=\"true\"
      android:layout_alignParentStart=\"true\"
      android:textSize=\"25dp\" />
      
   <TextView
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:text=\"New Text\"
      android:id=\"@+id/textView3\"
      android:layout_alignTop=\"@+id/textView2\"
      android:layout_alignParentRight=\"true\"
      android:layout_alignParentEnd=\"true\"
      android:layout_alignBottom=\"@+id/textView2\"
      android:layout_toEndOf=\"@+id/textview\"
      android:textSize=\"25dp\"
      android:layout_toRightOf=\"@+id/textview\" />
      
   <Button
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:text=\"login\"
      android:id=\"@+id/button\"
      android:layout_alignParentBottom=\"true\"
      android:layout_toLeftOf=\"@+id/textview\"
      android:layout_toStartOf=\"@+id/textview\" />
      
   <Button
      android:layout_width=\"wrap_content\"
      android:layout_height=\"wrap_content\"
      android:text=\"Cancel\"
      android:id=\"@+id/button2\"
      android:layout_alignParentBottom=\"true\"
      android:layout_toRightOf=\"@+id/textview\"
      android:layout_toEndOf=\"@+id/textview\" />

</RelativeLayout>

  There you go. Add these two lines

  •      android:focusable=”true”
  •      android:focusableInTouchMode=”true”

 in your top level layout and you have disabled edittext auto-focus.

Hire Developers

Direction: https://goo.gl/maps/K3inMgjZktJWTMRL8