首页 > 解决方案 > Android - 出现软键盘时 VideoView 隐藏的图像

问题描述

我知道这是一个常见问题,但我无法弄清楚。我有这个布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/greyB2"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <VideoView
        android:id="@+id/video_intro"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ImageView
        android:id="@+id/back_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_back"
        android:layout_marginTop="30dp"
        android:layout_marginStart="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.appcompat.widget.AppCompatEditText
        android:id="@+id/email_field"
        android:layout_width="320dp"
        android:layout_height="wrap_content"
        android:background="@drawable/white_borders_et"
        android:fontFamily="@font/exo_bold"
        android:hint="@string/sign_in_email"
        android:inputType="textEmailAddress"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:textAlignment="center"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/access_btn"/>

    <Button
        android:id="@+id/access_btn"
        style="@style/ButtonRed"
        android:layout_width="150dp"
        android:layout_height="47dp"
        android:text="@string/intro_access"
        android:textAllCaps="false"
        android:textSize="20sp"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

当点击 EditText 后出现键盘时,back_icon ImageView 被向上推。

我在清单中尝试了 android:windowSoftInputMode="adjustPan"和其他参数,但没有任何效果。提前致谢

编辑:对不起,我忽略了这个问题,但后来我意识到这是一切的原因:我有一个全屏 VideoView(更新了 xml 代码)。当键盘消失时,back_icon 就像被 VideoView “混淆”一样(图标不再可见但可点击,点击时会触发点击监听器。)。即使我给 back_icon 提升,问题仍然存在。

标签: androidandroid-layoutandroid-fragments

解决方案


解决方案很简单:

在活动标签中添加android:windowSoftInputMode="stateVisible|adjustResize"清单文件中。如下:

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

推荐阅读