我想在我的应用程序中使用不同的fragments
实现底部导航栏,并且每个fragment
包含不同的FloatingActionButton
,如果我单击浮动操作,则将打开新活动。有可能的?。任何人都可以提供代码或引用文档或视频来帮助我。
这是我的应用程序,我想在其中添加FAB,并在不同的片段中添加不同的FAB:
打开您的片段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
这里是一个YT视频,解释了如何创建底部导航。
完成底部导航的创建后,只需在所需的每个片段中添加一个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'