EditText is covered by Keyboard

2019-07-07 08:52发布

问题:

I am having a EditText in the hierarchy of

<CoordinateLayout>
...
    <NestedScrollView>
    ...
        <RelativeLayout> <!-- This is inside an included xml layout -->
        ...
            <EditText
                android:id="@+id/rateCalculator"
                android:layout_width="wrap_content"
                android:layout_height="48dp"
                android:background="@color/colorPrimary"
                android:inputType="number"
                android:maxLength="5"
                android:gravity="center"
                android:textColor="#FFFFFF"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:paddingLeft="60dp" />
        </RelativeLayout>
    </NestedScrollView>
</CoordinateLayout>

The EditText is being covered by the android soft-keyboard when it is being on focus! So I am unable to see what is being typed while typing!

Update:

This is my manifest code. Doesn't help!

<activity
        android:name=".OfferRide"
        android:label="@string/title_activity_offer_ride"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan"
        android:theme="@style/AppTheme.NoActionBar" />

回答1:

Removing the gravity from the EditText made it! It seems to be a bug.

<EditText
    android:id="@+id/rateCalculator"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:background="@color/colorPrimary"
    android:inputType="number"
    android:maxLength="5"
    android:textColor="#FFFFFF"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:paddingLeft="60dp" />


回答2:

You can try adjustPan, adjustResize options available for windowSoftInputMode in your AndroidManifest as follows:

<activity
    ...
    android:windowSoftInputMode="adjustPan" >
</activity>

You can learn more about it from here



回答3:

Depending on behavior you want to get, you can use android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan" on your activity declaration in Manifest.



回答4:

Here is the full doc: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] > 

How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things: The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention. The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard. The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >

Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.

Flags:

  • "stateUnspecified"
  • "stateUnchanged"
  • "stateHidden" - The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • "stateAlwaysHidden"
  • "stateVisible"
  • "stateAlwaysVisible"
  • "adjustUnspecified"
  • "adjustResize"

Or sometimes java will do that:

EditText edtView=(EditText)findViewById(R.id.editTextConvertValue);
    edtView.setInputType((InputType.TYPE_NULL);

Take a look:

https://stackoverflow.com/a/6122733/4409113