通常,当显示Snackbar时,浮动动作按钮向上移动,然后在Snackbar隐藏时向下移动到它的正常位置。在6.0.1之前,我已经在所有android版本中测试了我的应用程序,并且一切都如期而至。
不幸的是,在Android6.0.1上,在Snackbar消失之后,浮动动作按钮在软键盘下掉了一半。
根据安卓的指导原则,我使用CoordinatorLayout
作为父布局。我也尝试过:android:windowSoftInputMode="adjustResize"
在Manifest文件中。
<?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>
这是什么虫子吗?或者有什么方法可以通过编程来处理这个问题呢?
更新:我已经发现,当我滑动关闭Snackbar手动,FAB回到它的正常位置。但是,如果我让它自己隐藏/解散它,它就会产生问题。
使用@Muhammad Faisal Hyder
:Make FAB respond to Soft Keyboard show/hide changes建议的方法,我得到了以下结果:
任何建议都是非常感谢的。谢谢。
发布于 2017-01-07 07:03:23
我已经回答了另一个人提出的问题,你可以尝试this帖子,是的,有一个编程方法来处理它,我们需要扩展CoordinatorLayout.Behavior<FloatingActionButton>
和重写方法来实现FAB在滚动(隐藏和显示)和在快餐店或键盘上弹出的适当行为,这样Fab也会相应地移动。
编辑后的 :
上面提到的答案对我有用,你也可以试试这些。
添加:<android.support.design.widget.CoordinatorLayout/>
中的android:fitsSystemWindows="true"
如果上面不起作用,那么,
添加:android:windowSoftInputMode="adjustResize"
到您在Manifest.xml
中的活动
希望它能帮到你。
https://stackoverflow.com/questions/41518652
复制相似问题