【发布时间】:2021-01-01 12:10:00
【问题描述】:
我有一个场景,我在主要活动中使用底部应用栏,这也是各种屏幕的 navhostfragment 和其他片段。
Navhost 片段(MainActivity)
在配方片段上显示一个工厂是可见的。问题是我只希望这个工厂在配方片段上,而不是在其他工厂上。在其他人身上,我只想要底部的应用栏。
如何在不为每个片段创建应用栏的情况下解决此问题?
mainactivity xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="10dp"
app:fabCradleVerticalOffset="10dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:background="@android:color/transparent"
app:menu="@menu/bottom_appbar" />
</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:contentDescription="@string/app_name"
android:src="@drawable/ic_baseline_add_24"
app:layout_anchor="@id/bottomAppBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
当在底部应用程序栏中单击项目时,我设法显示不同的片段,但不想在配方片段以外的片段上显示 fab。
我正在使用 Kotlin,所以有一个解决方案会很有帮助。
【问题讨论】:
-
请不要仅仅因为您使用 android-studio 标签而标记问题:Android Studio 标签应该仅在您对 IDE 本身有疑问时使用,而不是您在其中编写(或想要编写)的任何代码。请参阅 when is it appropriate to remove an IDE tag、How do I avoid misusing tags? 和 the tagging guide。请改用 [android] 或其他相关标签。
-
好的!下次会记住这一点。
标签: android android-layout kotlin android-fragments frontend