Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Edit Text Covered By Keyboard on Second Tap

So I have an EditText that does not get covered by the keyboard the first time around. Then when you close the keyboard and tap the edittext again it covers the edittext.

I have spent hours researching this issue and have come to the conclusion it has something to do with these two properties of the edit text.

android:inputType="number"
android:gravity="center"

If I remove either one of those the adjustPan (as put in my manifest) works all the time as promised. Seems to be an Android bug. But I need both of these lines in my edit text. What is the best way to solve this problem?

Here is a slightly condensed version of xml:

<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:background="@color/colorPrimary"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">


<LinearLayout
    android:id="@+id/buttons_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:weightSum="5">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/generate_button"
        android:layout_width="match_parent"
        android:layout_height="@dimen/button_height"
        android:layout_marginBottom="@dimen/button_margin"
        android:layout_marginEnd="0dp"
        android:layout_marginLeft="@dimen/button_margin"
        android:layout_marginRight="0dp"
        android:layout_marginStart="@dimen/button_margin"
        android:layout_marginTop="@dimen/button_margin"
        android:layout_weight="1"
        android:background="@color/buttonColor"
        android:elevation="@dimen/button_elevation"
        android:foreground="?attr/selectableItemBackground"
        android:text="@string/generate"
        android:textColor="@color/colorPrimary"
        android:textSize="@dimen/generate_button_title_size"
        android:textStyle="bold" />

    <android.support.v7.widget.AppCompatImageButton
        android:id="@+id/copy_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/button_margin"
        android:layout_weight="4"
        android:adjustViewBounds="true"
        android:background="@color/buttonColor"
        android:elevation="@dimen/button_elevation"
        android:foreground="?attr/selectableItemBackground"
        android:padding="@dimen/button_margin"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_copy"
        android:tint="@color/colorPrimary" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/buttons_layout"
    android:orientation="vertical"
    android:weightSum="10">

    <GridLayout
        android:id="@+id/grid_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="6"
        android:animateLayoutChanges="true">
    </GridLayout>


    <TextView
        android:id="@+id/total_text_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:gravity="center"
        android:text="11"
        android:textSize="@dimen/toolbar_title_size"
        android:textStyle="bold" />

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="2"
        android:textColorHint="@color/textColorHint">

        <EditText
            android:id="@+id/num_rolls_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:hint="@string/number_of_rolls"
            android:inputType="number"
            android:maxLength="@integer/edit_text_max_length"
            android:maxLines="1"
            android:text="4"
            android:textColor="@color/textColor"
            android:textSize="@dimen/edit_text_text_size"/>

    </android.support.design.widget.TextInputLayout>

</LinearLayout>

Here is what it should look like every time... enter image description here

Here is what it looks like on the second tap currently (keyboard covers edittext)... enter image description here

EDIT: I have discovered the keyboard works fine when using Android 7.0. I don't think it works on anything below that. Was this a bug that was recently fixed or something?

Also, I have included android:windowSoftInputMode="adjustPan|stateHidden" in both my application and activity part of my manifest but that doesn't seem to fix it.

like image 869
Jared Avatar asked Jul 31 '17 03:07

Jared


People also ask

How do I turn off edit text on android?

What should I set to disable EditText? It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.

How do I hide the keyboard by one tap outside of an EditText?

and put the following code in the onTouch method. InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);

Which widgets allows us to edit text on screen?

Widget refers to the elements of the UI (User Interface) that helps user interacts with the Android App. Edittext is one of many such widgets which can be used to retrieve text data from user.

How to show soft keyboard based on Android edittext is focused?

This example demonstrates how do I show soft keyboard based on Android EditText is focused. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.java

How do I change the return button in Android soft keyboard?

First you need to set the android:imeOptionsattribute equal to “actionDone”for your target EditText as seen below. That will change your ‘RETURN’ button in your EditText’s soft keyboard to a ‘DONE’ button. * example_edittext.xml

How to change keyboard language on Android phone?

Then, this is the time you need to follow the steps on how you switch keyboards on Android. To check your phone’s Android keypad settings, you need to tap the Settings menu. Then you should look for the “Personal” section. You may need to scroll down to find it. You should tap on “Personal” and then press “Language & Enter” thereafter.

How to install a custom keyboard on an Android phone?

In this way, a custom Android keyboard can be installed. For this you should go to your “Settings” and then press “More”. Then tap “Application Manager” and choose “Google Keyboard”. Step 3: You will then have to go to the website where the phone keypad favourite files can be downloaded.


2 Answers

Add this in your manifest for activity. It works fine

 <activity android:name=".Views.UI.MainActivity"
        android:windowSoftInputMode="stateHidden|adjustResize">
like image 77
Jyoti Sharma Avatar answered Sep 28 '22 15:09

Jyoti Sharma


Try changing adjustPan to adjustResize for the activity config in manifest file, as the document suggested it.

This (adjustPan) is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

EDIT

If you don't want the views to be crushed/adjusted when keyboard is opened, add a ScrollView to your root RelativeLayout. So that when adjustResize will scroll the view accordingly instead of "crushing" them.

Hope this helps!

like image 30
Jiyeh Avatar answered Sep 28 '22 13:09

Jiyeh