Android 软键盘隐藏操作栏

Android 软键盘隐藏操作栏,android,android-activity,android-actionbar,android-softkeyboard,android-appbarlayout,Android,Android Activity,Android Actionbar,Android Softkeyboard,Android Appbarlayout,我有一个简单的活动,有一个文本视图,后面是两个编辑文本。当我开始打字时,软键盘会向上推布局并隐藏操作栏,我将无法选择/复制/粘贴文本 我的活动如下所示: 当我开始键入时,操作栏会隐藏,如下所示-更重要的是,请注意,即使文本高亮显示,也会丢失普通的复制粘贴栏: 如何确保操作栏不隐藏 我尝试过SO的其他一些技巧(比如使用滚动视图),但都没有奏效 该应用程序是使用Android Studio 1.4.1向导创建的,带有抽屉活动 在我的活动清单中,我正在使用adjustPan。我不想使用调整大小

我有一个简单的活动,有一个文本视图,后面是两个编辑文本。当我开始打字时,软键盘会向上推布局并隐藏操作栏,我将无法选择/复制/粘贴文本

我的活动如下所示:

当我开始键入时,操作栏会隐藏,如下所示-更重要的是,请注意,即使文本高亮显示,也会丢失普通的复制粘贴栏:

如何确保操作栏不隐藏

  • 我尝试过SO的其他一些技巧(比如使用滚动视图),但都没有奏效
  • 该应用程序是使用Android Studio 1.4.1向导创建的,带有抽屉活动
  • 在我的活动清单中,我正在使用adjustPan。我不想使用调整大小

    android:windowSoftInputMode=“stateAllwayshidden | adjustPan”

我的活动在这里:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/navigation_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".MainActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/app_theme.app_bar_overlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/app_theme.popup_overlay" />

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

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/activity_margin"
            android:fillViewport="true"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:background="@android:color/darker_gray"
                android:text="My holiday story here." />

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/activity_margin" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/gap_normal"
                android:gravity="top"
                android:text="My Holiday in Europe" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:gravity="top"
                android:text="My holiday story is blah blah blah blah blah blah blah blah blah..." />

        </LinearLayout>


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

    <com.magicparcel.app.mysampleapp.ui.CustomNavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/navigation_drawer_header"
        app:itemIconTint="@color/app_grey_500"
        app:menu="@menu/drawer_main" />

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

尝试在工具栏中添加
app:layout\u collapseMode=“pin”

<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_collapseMode="pin"
            app:popupTheme="@style/app_theme.popup_overlay" />

在AppBarLayout中添加工具栏,并添加AppBarOverLay和PopOverlay主题

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">

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

styles.xml

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

步骤1:从每个视图中删除
fitsSystemWindow
属性,并将其添加到清单中的活动标记中

步骤2
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
从线性布局中删除此行。这是实际推动上面的actionbar的代码


这两个步骤解决了我的问题,希望对您也有帮助。

谢谢,但我需要使用adjustPan,而不是adjustResize。您是否尝试过将除AppBarLayout之外的所有视图包装到ScrollView中?下面的答案是否适用于您@henry000Hi,只是为了澄清一下。对于位于EditText字段上方的任何其他视图,我们应该做什么。例如在EditText上面有几个布局,我们希望使用adjustPan。在本例中,当我们选择EditText时,上面的所有视图都会向上移动,其中一些视图(如ActionBar)会隐藏。我应该怎么做,在选择时在EditText上方保存一些版面,让其他版面向上移动?我不明白你的意思,我应该怎么做,在选择时在EditText上方保存一些版面,让其他版面向上移动?