简体   繁体   English

在Android 6.0.1中显示Snackbar之后,FAB进入键盘下方

[英]FAB goes under keyboard after Snackbar is shown in android 6.0.1

Normally when Snackbar is shown, Floating Action Button shifts up and then shifts down to its normal position when Snackbar hides. 通常,当显示Snackbar时,浮动动作按钮会向上移动,然后在Snackbar隐藏时向下移动到其正常位置。 I have tested my application in all android versions before 6.0.1 and everything works as expected. 我已经在6.0.1之前的所有android版本中测试了我的应用程序,并且一切正常。

Unfortunately on android 6.0.1, after the Snackbar goes away the Floating Action Button goes half under the soft keyboard. 不幸的是,在Android 6.0.1上,在Snackbar消失后,Floating Action Button在软键盘下移了一半。

在此处输入图片说明

As per the Android guidelines I have CoordinatorLayout as the parent layout. 根据Android准则,我将CoordinatorLayout作为父布局。 And I have also tried: android:windowSoftInputMode="adjustResize" in the Manifest file. 而且我也尝试过:清单文件中的android:windowSoftInputMode="adjustResize"

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:id="@+id/myCoordinatorLayout"
    tools:context="com.example.myapp.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        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:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <include layout="@layout/content_main"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@mipmap/ic_add_white_24dp" />

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

Is this some sort of bug? 这是某种错误吗? or is there any way to handle this programatically? 或有什么办法以编程方式处理此问题?

UPDATE: I have discovered that when I swipe to dismiss the Snackbar manually, the FAB comes back to its normal position. 更新:我发现,当我手动滑动以关闭快餐栏时,FAB返回到其正常位置。 But if I let the snackbar until it hides/dismisses by itself, it will create the problem. 但是,如果我让快餐栏直到其自身隐藏/散开,就会产生问题。

Using this approach suggested by @Muhammad Faisal Hyder : Make FAB respond to Soft Keyboard show/hide changes I am getting the following result: 使用@Muhammad Faisal Hyder建议的这种方法: 使FAB响应软键盘显示/隐藏更改,我得到以下结果:

在此处输入图片说明

Any suggestions are highly appreciated. 任何建议都将受到高度赞赏。 Thanks. 谢谢。

I have given answer to this question asked by another person, you can try this post, yes there is a programming way to handle it, we need to extend CoordinatorLayout.Behavior<FloatingActionButton> and override methods to achieve appropriate behaviours of FAB on scrolling (to hide and show) and on snack bar or keyboard pops up so Fab also moves accordingly. 我已经回答了另一个人提出的这个问题,您可以尝试这篇文章,是的,有一种编程方法可以处理它,我们需要扩展CoordinatorLayout.Behavior<FloatingActionButton>并重写方法以实现滚动时FAB的适当行为(隐藏和显示),然后在小吃店或键盘上弹出,这样Fab也会相应移动。

After EDIT : 编辑后:

Above referenced answer works for me, well you can try these as well. 以上引用的答案对我有用,那么您也可以尝试这些。

add : android:fitsSystemWindows="true" in <android.support.design.widget.CoordinatorLayout/> <android.support.design.widget.CoordinatorLayout/>添加android:fitsSystemWindows="true"

If above doesn't work, still, then, 如果上述方法仍然无效,那么,

add : android:windowSoftInputMode="adjustResize" to your activity in Manifest.xml 向您在Manifest.xml的活动添加android:windowSoftInputMode="adjustResize"

Hope it will help you out. 希望它能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM