当键盘出现在 Fragment 中时,Android EditText 键入的文本不显示

标签 android android-fragments android-edittext

我在带有 textView、Button 和 ImageView 的 Fragment 中使用 EditText。

我的问题是:

出现键盘时我看不到我在输入什么。

我的 XML 代码是:

 <FrameLayout 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="@android:color/background_light"
        android:clickable="true">

        <!-- TODO: Update blank fragment layout -->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="190dp"
                        android:background="@drawable/header" />

                    <TextView
                        android:id="@+id/head"
                        style="@style/Base.TextAppearance.AppCompat.Large"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="sub heading" />

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/request_til"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <EditText
                            android:id="@+id/request_et"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="Enter your Name and Address here"
                            android:maxLines="10"
                            android:minLines="6" />
                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>

            </ScrollView>

            <Button
                android:id="@+id/request_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/colorPrimary"
                android:text="Button"
                android:textColor="@android:color/background_light" />
        </RelativeLayout>
    </FrameLayout>

截图: 当键盘出现时:我看不到我在输入什么 enter image description here

打字后键盘消失,然后我才能看到我输入的内容: enter image description here

请有人帮我解决我的问题

最佳答案

虽然现在回复这个帖子已经很晚了。我遇到了同样的问题并用

解决了
window.setFlags(
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
)

我根据屏幕要求动态设置了这个标志。

关于当键盘出现在 Fragment 中时,Android EditText 键入的文本不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39836296/

相关文章:

java - 无法执行操作,因为插入数据库时​​没有当前事务

java - 尝试将 RowItem 添加到 ListView 时 Android IndexOutOfBoundsException

java - 将数据从 Activity 传递到 Fragment 会导致 "ScrollView can host only one direct child"错误

android - 如何更改editText提示位置

java - Arraylist 元素在最后一个索引之后重复

android - 无法在 Android 上使用 ServerSocket

android - 如何在 View 失去焦点时屏蔽 EditText 中的文本。

android - 有没有办法修复 EditText 中的字母宽度?

android - 通过删除子 fragment 获取 IllegalStateException

java - 无法在 UserRecyclerAdapter 类中使用 "custom_list_users.xml"来膨胀 fragment