如何以编程方式显示/隐藏BottomAppBar? [英] How to show/hide BottomAppBar programmatically?
本文介绍了如何以编程方式显示/隐藏BottomAppBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用BottomAppBar,并且希望能够像AppBarLayout中的setExpanded
一样以编程方式隐藏或显示它.
I try to use an BottomAppBar and I would like to be able to hide or show it programmatically like a setExpanded
in an AppBarLayout.
我的布局就像
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nested"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<fragment
android:id="@+id/navHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/home_nav" />
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimary"
app:fabAlignmentMode="center"
app:hideOnScroll="true"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIcon="@drawable/ic_menu"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我尝试使用AppBottomBar的行为,但是它不起作用.
I tried to use the behavior of the AppBottomBar but it doesn't work.
推荐答案
在底部应用栏上调用performShow()
和performHide()
即可完成所需的操作.
Calling performShow()
and performHide()
on the bottom app bar will do what you want.
这篇关于如何以编程方式显示/隐藏BottomAppBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文