android - 如何防止软键盘只上推工具栏?

标签 android android-layout android-softkeyboard

我有一个布局,顶部有一个工具栏和几个 EditText View :

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/my_toolbar">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text1"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text2"/>

            ...

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text7"/>
    </LinearLayout>

</RelativeLayout>

当靠近屏幕底部的一些EditText打开软键盘时,整个屏幕(包括工具栏)将被向上推。有什么方法可以让软键盘上推整个屏幕,除了工具栏(修复工具栏)?

一些现有的answers实际上可以固定整个屏幕,但是靠近底部的EditText也可能被软键盘挡住。

谁能给我一个好的解决方案?

最佳答案

将 android:fitsSystemWindows="true"放在第一个相对布局中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
....
....
</RelativeLayout>

并在 list 中添加这个

android:windowSoftInputMode="adjustPan"

关于android - 如何防止软键盘只上推工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34351274/

相关文章:

java - 将base64异常字符串编码和解码为sql server 2008 r2

java - 为 Eclipse/Android 开发编译标志

android - 将 TextView 对齐到 RelativeLayout 的中心

java - 方法 getSupportFragmentManager() 未定义类型 new AdapterView.OnItemClickListener(){}

带有 2 个标签的 Android 自定义键盘(右上角的主要标签和小标签)

android - 获取光标位置 Android 键盘

Android:无法实例化 Activity

android - 集中化 TabLayout

android - 获取Android中虚拟键盘的高度

java - 如何在 Java 中将 If 语句组合成一个更大的 If 语句