如何集成可扩展的浮动操作按钮

时间:2021-01-01 07:59:24

标签: java android

我是使用 Java 进行 android 开发的初学者, 我试过网上冲浪,但无济于事。 我可以用来制作可扩展的浮动操作按钮的库的名称是什么,如下图所示。
请帮忙。

image

1 个答案:

答案 0 :(得分:1)

我正在查看一些源代码。我找到了一个最好的可扩展 FAB(浮动操作按钮)

让我添加这些源代码。 将其添加到 build.gradle

implementation 'com.nambimobile.widgets:expandable-fab:1.0.2'

在布局中添加以下源代码

<!-- This is NOT a root view, but should be a child of whatever root view you 

choose (CoordinatorLayout, ConstraintLayout, etc) -->
<com.nambimobile.widgets.efab.ExpandableFabLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  
  <!-- The next 3 Views will only display in portrait orientation -->          
  <com.nambimobile.widgets.efab.Overlay
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:overlay_orientation="portrait"/>
  <com.nambimobile.widgets.efab.ExpandableFab
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="@dimen/ui_margin_medium"
    android:layout_marginEnd="@dimen/ui_margin_medium"
    android:layout_marginRight="@dimen/ui_margin_medium"
    app:efab_orientation="portrait"/>
  <com.nambimobile.widgets.efab.FabOption
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:fab_orientation="portrait"
    app:label_text="Portrait Option 1"
    android:onClick="onClickPortraitOption1"/>

  <!-- The next 3 Views will only display in landscape orientation -->
  <com.nambimobile.widgets.efab.Overlay
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:overlay_orientation="landscape"/>
  <com.nambimobile.widgets.efab.ExpandableFab
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="@dimen/ui_margin_medium"
    android:layout_marginEnd="@dimen/ui_margin_medium"
    android:layout_marginRight="@dimen/ui_margin_medium"
    app:efab_orientation="landscape"/>
  <com.nambimobile.widgets.efab.FabOption
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:fab_orientation="landscape"
    app:label_text="Landscape Option 1"
    android:onClick="onClickLandscapeOption1"/>
            
</com.nambimobile.widgets.efab.ExpandableFabLayout>

然后,您可以像使用 Java 文件中的按钮一样使用这些 FAB。

让我补充一下link