微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android:键入时将TextInputEditText保留在视图中

我正在尝试使用几个TextInputEditText元素创建一个活动.这些放置在页面的大约一半处,导致它们在出现时被键盘覆盖.因此,我正在尝试在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片段

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

试图解决方

>将windowSoftInputMode =“adjustPan”添加到AppManifest.xml中的相关活动(我也根据其他StackOverflow建议尝试了adjustResize和adjustPan | adjustnothing)
>将ConstraintLayout放在ScrollView中
>向所述ScrollView添加android:isScrollContainer =“false”
>重新创建布局文件,仅将ConstraintLayout和TextInputEditText约束到所述布局的底部
>将TextInputEditText更改为EditText并删除TextInputLayout
>将ConstraintLayout更改为RelativeLayout

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

解决方法:

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

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

希望某人有一天会觉得这很有用.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。