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 topmost edit text and the virtual keyboard pops up. This hides the 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”
Conclusion
After attempting all that was conceivably doable to clear up this confusing matter, you can finally get rid of that annoying emphasis and get on with your assignment as you were doing before. Or you can hire UI/UX developers to overcome this issue. Web Idea Solution is ready to serve you with the top potential.