Space between Edittext and keyboard on android
I would like to know if it is possible to put a margin to space the edittext keyboard so as not to get so close like this:
The xml of how I am declaring the EditText:
<EditText
android:id="@+id/editTextNome"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="23px"
android:layout_marginRight="23px"
android:paddingLeft="7dp"
android:layout_marginBottom="40dp"
android:hint="@string/nome_login"
android:inputType="textCapSentences"
android:background="@drawable/rounded_border"/>
2 answers
Have you tried to set android:windowSoftInputMode in your activity as follows:
android:windowSoftInputMode="adjustResize"
Or
android:windowSoftInputMode="adjustPan"
By definition, according to the documentation,
AdjustResize : the main activity window is always resized to make room for the on-screen software keyboard.
AdjustPan : the main activity window is not resized to make room for the on-screen software keyboard. Instead, it moves the contents of the window automatically so that the current focus is never superimposed by the keyboard and users can always see what they type. Typically, this behavior is less desirable than resizing, as the user may need to close the software keyboard to access and interact with the overlapping parts of the window.
But from the context, I believe that in your case the adjustResize
works, if it does not work, arrow in Activity android:windowSoftInputMode="adjustPan"
, along with a android:paddingBottom
in the EditText
, with the value you deem necessary and Arrow also: android:gravity="bottom"
.
Thanks @ Mathias, the adjustResize
worked well, it follows how all the xml of the field was if it serves as a reference for someone:
In manifest file:
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize|stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And in the activity xml:
<LinearLayout
android:id="@+id/menu_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:orientation="vertical"
android:visibility="invisible"
android:layout_marginBottom="35dp">
<EditText
android:id="@+id/editTextNome"
android:layout_width="match_parent"
android:layout_marginLeft="20px"
android:layout_marginRight="20px"
android:paddingLeft="5dp"
android:layout_marginBottom="35dp"
android:hint="@string/nome_login"
android:layout_height="40dp"
android:inputType="textCapSentences"
android:background="@drawable/rounded_border"
/>
<Button
android:id="@+id/botaoEntrar"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/botao_entrar"
android:elevation="0dp"
android:background="@drawable/rounded_button"
android:textColor="@color/white"
android:onClick="abrirFicha"
/>
</LinearLayout>