我正在尝试使用几个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>.
希望某人有一天会觉得这很有用.