软键盘隐藏工具栏 [英] Soft Keyboard Hides Toolbar

查看:119
本文介绍了软键盘隐藏工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在布局中使用了工具栏.每当我打开活动并专注于编辑文本时,它就会隐藏工具栏.请看下面的图片

I have used Toolbar in my layout. Whenever I open the activity, and focus on the edit-text, it hides the toolbar. Please see below pictures

下面是我的布局文件:

<LinearLayout 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:orientation="vertical"
tools:context="com.example.sampleactivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    android:background="@color/color_theme"
    android:minHeight="?attr/actionBarSize">

    <TextView
        android:id="@+id/toolbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="App"
        android:textColor="@color/white"
        android:textSize="24sp" />

    <Button
        android:id="@+id/past_locations"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="Next"
        android:textColor="@color/white"
        style="?android:attr/borderlessButtonStyle"/>

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

<LinearLayout
    android:id="@+id/mapLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>


    <EditText
        android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Title"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:singleLine="true"
        />

    <AutoCompleteTextView
        android:id="@+id/tags"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:maxLines="3"
        />

</LinearLayout>

使用android:windowSoftInputMode="adjustPan"也无济于事.

如何避免在键盘打开时隐藏工具栏.

How can I avoid hiding my toolbar when keyboard opens up.

推荐答案

在AndroidManifest.xml中添加android:windowSoftInputMode="adjustResize"解决了我的问题,例如:

Adding android:windowSoftInputMode="adjustResize" in AndroidManifest.xml solved my issue, like:

 <activity
        android:name=".MainActivity"
        android:label="@string/activity_main"
        android:windowSoftInputMode="adjustResize">
 </activity>

这篇关于软键盘隐藏工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆