Wednesday, December 26, 2018

Stop showing soft keyboard on Activity start | Android programming


If the first element in the Activity is an EditText, it will get focus when the Activity starts, and the soft keyboard will show up.

There are many ways to solve this issue if you don't want the soft keyboard pop up. Here is a simple and interesting trick that only makes small updates on the layout XML files.

Add the attributes to the parent element of the first EditText. The EditText will not get focus at the start up and thus the soft keyboard will not show. The code to be added is highlighted below:

<LinearLayout
    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:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/some_iput"/>

   ...

No comments:

 
Get This <