【问题标题】:Android - image hidden by VideoView when soft keyboard appearAndroid - 出现软键盘时 VideoView 隐藏的图像
【发布时间】:2021-01-03 14:20:38
【问题描述】:

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

<?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 提升,问题仍然存在。

【问题讨论】:

  • 在我在下面发布的解决方案中,它工作得很好。你是如何将它添加到清单文件中的?让我们看看你的清单文件。

标签: android android-layout android-fragments


【解决方案1】:

解决方法很简单:

android:windowSoftInputMode="stateVisible|adjustResize" 添加到您的清单文件 中的活动标记中。如下:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    • 2012-10-28
    相关资源
    最近更新 更多