gpt4 book ai didi

Android:键入时保持 TextInputEditText 在 View 中

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:42 25 4
gpt4 key购买 nike

我正在尝试使用几个 TextInputEditText 元素创建一个 Activity 。它们位于页面下方大约一半的位置,导致它们在出现时被键盘覆盖。因此,我尝试在 AppManifest.xml 中使用 windowSoftInputMode="adjustPan" 来滚动屏幕以在键入时保持文本框可见。

然而,所有这方面的尝试似乎都失败了。下面是我正在使用的布局层次结构,跟进了一些我已经尝试过但无济于事的解决方案示例。

布局 xml

<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:isScrollContainer="false">

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

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

<android.support.design.widget.TextInputEditText
android:id="@+id/inputAText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.design.widget.TextInputLayout>

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

<android.support.design.widget.TextInputEditText
android:id="@+id/inputBText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.design.widget.TextInputLayout>

</android.support.constraint.ConstraintLayout>

</ScrollView>

AndroidManifest.xml fragment

<activity
android:name=".activities.MyActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="sensorPortrait"
android:theme="@style/AppTheme.NoActionBar" />

尝试的解决方案

  1. windowSoftInputMode="adjustPan"添加到AppManifest.xml中的相关activity(我也尝试过adjustResizeadjustPan|adjustNothing 根据其他 StackOverflow 建议)
  2. ConstraintLayout 放在 ScrollView
  3. android:isScrollContainer="false" 添加到所述 ScrollView
  4. 重新创建布局文件,仅将 ConstraintLayoutTextInputEditText 限制在所述布局的底部
  5. TextInputEditText 更改为 EditText 并移除 TextInputLayout
  6. ConstraintLayout 更改为 RelativeLayout

对于应该是一个相当简单的实现,我不知所措。任何进一步的建议表示赞赏。如有必要,我很乐意提供更多代码示例。

最佳答案

发现问题了!在我的主题中,我声明了 <item name="android:windowTranslucentStatus">true</item> .出于某种原因,这打破了 windowSoftInputMode="adjustPan" ,因此我删除了它。

为了保持状态栏透明,我使用<item name="android:statusBarColor">@color/transparent</item> .

希望有一天有人会发现这很有用。

关于Android:键入时保持 TextInputEditText 在 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53267380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com