【问题标题】:Hide Keyboard does not re-expand the layout隐藏键盘不会重新展开布局
【发布时间】:2015-07-21 16:51:30
【问题描述】:

我用AppBarLayoutToolbar 实现了CoordinatorLayout,以在滚动时隐藏工具栏,一切正常。
当我实现搜索视图时出现问题。
这是我的activity_main 布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <View
            android:id="@+id/appbar_bottom"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/transparent"
            android:visibility="invisible"/>

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

还有我的fragment_layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/projects_swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/projects_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

</android.support.v4.widget.SwipeRefreshLayout>

正常布局RecyclerView

隐藏键盘时的问题。

【问题讨论】:

标签: android android-softkeyboard android-recyclerview android-design-library


【解决方案1】:

您可以控制 appBarLayout 的可扩展行为:

首先通过将这些行放在 Manifest 中,您可以禁用由于键盘在显示和隐藏时的应用栏折叠效果。

<activity android:name="MyActivity"
   ...
   android:windowSoftInputMode="adjustNothing"
   ...
</activity>

然后,您可以随时展开/折叠应用栏:

appbar.setExpanded(true); / appbar.setExpanded(false);

当 EditText 有焦点时你可以折叠,当外部视图接触时展开..

(someView.setOnTouchListener ...)

【讨论】:

    【解决方案2】:

    在这里回答: Android : Showing keyboard moves my components up, i want to hide them instead

    将 android:windowSoftInputMode="adjustPan" 添加到 manifest - 到相应的活动中:

    <activity android:name="MyActivity"
       ...
       android:windowSoftInputMode="adjustPan"
       ...
    </activity>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-27
      • 2016-03-10
      • 2021-03-29
      • 2014-07-18
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多