android - RecyclerView 在 SoftKeyboard 可见时隐藏 Toolbar 和布局

标签 android toolbar android-softkeyboard android-recyclerview

我有一个完全像这样的问题LINK ,布局中的相同情况和相同组件。 唯一的区别是工具栏,但显然我使用的是 appcompat 并且行为是相同的。

注意,不仅toolbar被隐藏了,recyclerview的上半部分也被隐藏了。就像当软键盘可见时整个 fragment 被向上翻译一样。

我在 Activity 的 main.xml 中使用这样的工具栏:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/container_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

框架布局被替换为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:ignore="MergeRootFrame" >

    <!--<include layout="@layout/toolbar" />-->

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/primary"
        android:textColor="#FFFFFF"
        app:pstsIndicatorColor="#FFFFFF"
        app:pstsPaddingMiddle="true"
        android:maxHeight="20dp"
        android:elevation="5dp"
    />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    </LinearLayout>

在 View 寻呼机中,我有一个带有 recyclerview 的 fragment 布局标签:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="50dip"/>


    <EditText
        android:id="@+id/txtChatLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/txt_hint"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@+id/button1">
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_send"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

当我开始在 edittext 中输入文本时,整个布局上升,工具栏变得不可见(在屏幕之外)并且 recyclerview 不滚动,但它向上移动。

最佳答案

我遇到了同样的问题,@drakeet 解决方案对我有用: RecyclerView hides Actionbar when SoftKeyboard is opened

我在 Toolbar 和 RecyclerView 之间添加了一个空的 ScrollView,Toolbar 停止隐藏。

<include android:id="@+id/app_bar" layout="@layout/toolbar"/>

<!--Empty ScrollView needed so the recyclerview doesn't hide the toolbar-->
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ScrollView>

<view
    android:id="@+id/recycler_view"
    android:layout_below="@id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="android.support.v7.widget.RecyclerView"
    android:layout_above="@+id/message_layout"/>

关于android - RecyclerView 在 SoftKeyboard 可见时隐藏 Toolbar 和布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28529474/

相关文章:

android - 如何将此图标添加到我的操作栏?

android - 无法在设备上安装 apk

Android 工具栏项目未显示?

android - 我可以在没有 EditText 的情况下使用软键盘吗?

android - 使用最新的 WindowInset API 出现软键盘时如何调整对话框布局

android - 如何检测软件键盘在 Android 设备上是否可见?

java - SurfaceView 作为背景

android - 使用支持库 v21 设置 SearchView 小部件的样式

Qt/C++ : Icons not showing up when program is run

ios - 为什么当我点击文本字段时工具栏不显示?