Keyboard hides EditText when selected

别来无恙 提交于 2019-12-12 03:17:25

问题


I am facing an issue where the keyboard hides an editText when the editText is selected for the second time, the first time editText is selected the keyboard behaves as expected.

The issue only occurs when I set the editText input type to "NumberDecimal" but when it's set to "Default" the keyboard behaves normally as well.

I have tried the following without success:

android:windowSoftInputMode=“adjustResize"

below is a snippet from the layout file

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_marginTop="20dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:weightSum="1">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_gravity="center"
                    android:layout_marginLeft="10dp"
                    android:layout_weight="0.25"
                    android:background="@drawable/rounded_left_selected"
                    android:gravity="center"
                    android:text="@string/amount"
                    android:textColor="@color/white"
                    android:textSize="17dp"

                    android:textStyle="bold" />

                <EditText
                    android:id="@+id/transfer_amount"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_weight="0.55"
                    android:background="@drawable/white_unrounded_edittext"
                    android:ems="10"
                    android:gravity="center"
                    android:hint="@string/hint_amount"
                    android:maxLength="15"
                    android:textColor="@color/blue_light"
                    android:textSize="17dp"
                    android:inputType="numberDecimal"/>

                <TextView
                    android:id="@+id/trans_amount_cur"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.12"
                    android:background="@drawable/round_right_selected"
                    android:gravity="center"
                    android:text="JOD"
                    android:textColor="@color/white"
                    android:textSize="17dp" />
            </LinearLayout>

回答1:


Just remove the gravity on edittext, it seems to be a bug.

<EditText
                android:id="@+id/transfer_amount"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="0.55"
                android:background="@drawable/white_unrounded_edittext"
                android:ems="10"
                android:hint="@string/hint_amount"
                android:maxLength="15"
                android:textColor="@color/blue_light"
                android:textSize="17dp"
                android:inputType="numberDecimal"/>



回答2:


You can add android:windowSoftInputMode="adjustPan" in you manifest, into activity. I thing it is the best way



来源:https://stackoverflow.com/questions/33649063/keyboard-hides-edittext-when-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!