ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-01 10:24:15  阅读:171  来源: 互联网

标签:android android-layout android-softkeyboard mobile xml


我正在尝试使用几个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>.

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

标签:android,android-layout,android-softkeyboard,mobile,xml
来源: https://codeday.me/bug/20190701/1346041.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有