![](/img/trans.png)
[英]FloatingActionButton, which is anchored to BottomAppBar, disappears when the application is resumed
[英]How to hide FloatingActionButton which is anchored to BottomAppBar when the is hidden on scroll
當由於NestedScrollView
滾動而隱藏BottomAppBar
時,我試圖隱藏FloatingActionButton
。 當app:hideOnScroll="true"
設置時, BottomAppBar
隱藏成功,但FloatingActionButton
保持可見。 我的布局如下所示:
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nested_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
...
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_gravity="bottom"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
app:backgroundTint="@color/colorWhite"
android:requiresFadingEdge="vertical"
app:fabCradleRoundedCornerRadius="16dp"
app:fabCradleMargin="16dp"
app:fabCradleVerticalOffset="16dp"
app:hideOnScroll="true"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="64dp"
app:menu="@menu/bottom_menu"
app:elevation="0dp"
app:labelVisibilityMode="labeled"
android:background="@android:color/transparent"
app:itemTextColor="@color/colorPrimaryApp"
app:itemIconTint="@color/colorPrimaryApp"
app:itemBackground="@drawable/bvn_transparent_light_blue_color_selector"
android:layout_marginEnd="16dp"
/>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bnv_add"
android:tint="@color/sky"
android:backgroundTint="@color/sky"
app:layout_anchor="@+id/bottomAppBar"
tools:ignore="ContentDescription"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
有沒有一些沒有技巧的方法來做到這一點?
我設法使用一些技巧隱藏了 FloatingActionButton,如下所示:
val point = Point()
val startSize = fab.customSize
nested_view.viewTreeObserver.addOnScrollChangedListener {
windowManager.defaultDisplay.getSize(point)
when {
bottomAppBar.y + bottomAppBar.measuredHeight > point.y ->
{ fab.customSize = 1; fab.alpha = 0.0f}
else ->
{ fab.customSize = startSize; fab.alpha = 1f}
}
}
但我不喜歡它:) 它的行為有點奇怪:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.