当出现软键盘时,工具栏会向上移动 [英] Toolbar shifts up, when soft keyboard appears

查看:97
本文介绍了当出现软键盘时,工具栏会向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在键盘出现时调整活动布局的大小,但同时保持其工具栏位置不变.到目前为止,当我单击编辑文本并出现键盘时,所有屏幕都向上移动.

I want to make my activity layout resize when keyboard appears, but at the same time keep its toolbar position unchanged. So far all the screen shifts up, when I click on the edit text and the keyboard appears.

在出现键盘之前:

出现键盘后,工具栏不再可见:

After keyboard appears, the toolbar isn't visible anymore:

我想将键盘保持在原处,并在其下方移动图像. 我不能只在清单中指定android:windowSoftInputMode="adjustNothing",因为当键盘出现时,编辑文本将不再可见.

I would like to keep the keyboard in its place and shift below it the image. I can't just specify in the manifest: android:windowSoftInputMode="adjustNothing" , because the edit text will not be visible anymore, when the keyboard appears.

到目前为止,我使用以下代码:

So far, I use the following code:

在AndroidManifest.xml中:

In AndroidManifest.xml:

android:windowSoftInputMode="adjustPan|stateHidden"

在布局中:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:clickable="true"
    android:fitsSystemWindows="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context="studentplanner.mobile.yardi.com.studplan.presentation.activities.PersonalInformationActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/toolbar_and_button_height"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:elevation="4dp"
        android:background="@color/main">

        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/personal_information_text"
            android:textColor="@android:color/white"
            android:textSize="@dimen/medium2_text_size" />

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

    <ImageView
        android:id="@+id/background_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/extra_large5_dimen"
        android:layout_below="@+id/toolbar"
        android:scaleType="center"
        android:src="@drawable/userbackground" />

...

欢迎任何帮助!

推荐答案

我遇到了同样的问题.
当处理片段时,我将isScrollContainer放在framelayout内,它可以解决所有键盘问题.

i had the same issue.
when dealing with fragments i put isScrollContainer inside of the framelayout and it resolves all keyboard issues.

  <FrameLayout android:id="@+id/container_framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true"/>

这就是我所需要的.

但是如果您希望每个片段都基于ti,则可以通过在onCreateView片段回调中将容器设置为滚动容器来实现:

but if you want ti on a per fragment bases then do this by setting your container to scrolling container in onCreateView fragment callback:

@Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_type_barcode, container, false);
        container.setScrollContainer(true);

        return rootView;
    }

这篇关于当出现软键盘时,工具栏会向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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