Android键盘推高动作栏

时间:2017-09-12 08:32:43

标签: android android-layout layout

点击EditText表单后,弹出键盘并仅将actionbars推向第二个片段。

Before

After

我在ViewPager中使用MainActiviy。上面的截图位于3的第二个片段中。

这是第二个片段的布局。

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginBottom="30dp"
        android:background="@color/editTextColor"
        >
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inputType="text"
            android:hint="Query"
            android:ems="10"
            android:id="@+id/query"
            android:layout_weight="0.3"
            />

        <Button
            android:backgroundTint="@color/button1"
            android:textColor="@color/buttonText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawableTop="@drawable/search_picto"
            android:id="@+id/searchBooks"
            android:layout_weight="0.7"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:baselineAligned="false">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="2dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:drawableTop="@drawable/seat_info_picto"
                android:backgroundTint="@color/button1"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:id="@+id/seat_info"
                />
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:backgroundTint="@color/button1"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="2dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:drawableTop="@drawable/pt_room_picto"
                android:backgroundTint="@color/button1"
                android:text="시설 예약"
                android:id="@+id/room_reservation"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                />
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:backgroundTint="@color/button1"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="2dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:backgroundTint="@color/button1"
                android:drawableTop="@drawable/bookmark_picto"
                android:id="@+id/bookmarks"
                android:text="관심 도서"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                />
            <com.seokyeong.adw.sku_library.custormizes.SquareDrawableButton
                android:backgroundTint="@color/button1"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

我已尝试在adjustNothingadjustPan中添加MainActiviyAndroidManifest.xml选项。但它没有用。

同时添加getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 在我的片段类

如何阻止键盘破坏布局?

Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.seokyeong.adw.sku_library.activitys.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        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="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:background="@color/main_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

3 个答案:

答案 0 :(得分:1)

在活动的manifest.xml中尝试此操作

  android:windowSoftInputMode="adjustResize"

答案 1 :(得分:0)

  

从ViewPager应用中删除此行:layout_behavior =&#34; @ string / appbar_scrolling_view_behavior&#34;

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:background="@color/main_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

答案 2 :(得分:0)

尝试从app:layout_scrollFlags="scroll|enterAlways"视图中删除此行 - toolBar