我想在我的应用程序中使用不同的fragments
来实现底部导航栏,并且每个fragment
都包含不同的FloatingActionButton
,如果我点击浮动操作新活动将打开。有可能的?。任何人都可以提供代码或引用文档或视频来帮助我。
这是我的应用程序,我想在其中添加FAB,并在不同的片段中添加不同的FAB:
答案 0 :(得分:1)
打开您的片段UI xml文件。将FloatingActionButton
添加到要显示的位置:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_my_icon"
android:contentDescription="@string/submit"
android:layout_margin="16dp" />
摘自Google android文档:Add a Floating Action Button
答案 1 :(得分:1)
这是一个YouTube视频,介绍了如何创建底部导航。
完成底部导航的创建后,只需在所需的每个片段中添加一个FAB。在片段XML中包含以下代码。
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:src="@drawable/ic_add_alarm_black_24dp"
android:background="@color/colorAccent"
app:backgroundTint="@color/colorAccent"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
还将以下依赖项添加到gradle中。
implementation 'com.google.android.material:material:1.0.0'