我正在尝试将Cast按钮实现为浮动操作按钮,但我不知道该如何实现。
到目前为止,我已经在工具栏上使其正常运行,但我想尝试将其作为浮动操作按钮。
我尝试了以下方法,但它并不能像真正的浮动操作按钮那样工作。
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:hideOnScroll="true"
app:layout_scrollFlags="scroll|enterAlways|snap">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ib_monitors"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_photo_camera_black_24dp" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ib_videos"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_video_library_black_24dp" />
<androidx.appcompat.widget.AppCompatImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ib_settings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_settings_black_24dp" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ib_account"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_account_circle_black_24dp" />
</LinearLayout>
</com.google.android.material.bottomappbar.BottomAppBar>
<androidx.mediarouter.app.MediaRouteButton
android:id="@+id/media_route_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:backgroundTint="@color/fabBackgroundTint"
app:layout_anchor="@id/bar"
app:tint="@color/colorAccent"/>
<!--<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/fabBackgroundTint"
app:layout_anchor="@id/bar"
app:srcCompat="@drawable/ic_add_a_photo_black_24dp"
app:tint="@color/colorAccent" />-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
感谢任何技巧。