我正在嘗試創建與圖片類似的東西。我正在使用CoordinatorLayout,BottomAppBar和BottomNavigation,但底部應用欄需要一個浮動操作按鈕來在按鈕周圍創建底座。我需要浮動操作按鈕有一個影像和一個文本視圖,我將以編程方式更新它們。
有沒有辦法在不創建整個自定義底部應用欄的情況下實作這一目標?

uj5u.com熱心網友回復:
TextView您可以擁有一個透明的 FAB,并在其上使用您的自定義 Image & 繪制布局
與 FAB 類似,app:layout_anchor&app:layout_anchorGravity可用于布局以將其放置在 FAB 之上。
這是一個實作:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@ id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fab_cutout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
app:layout_anchor="@id/navigation" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
app:layout_anchor="@id/navigation"
app:layout_anchorGravity="center_horizontal">
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearance="@style/roundedimage"
app:srcCompat="@drawable/with_cart1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="99"
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@ id/navigation"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@android:color/holo_blue_dark"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:fabCradleMargin="10dp"
app:fabCradleVerticalOffset="8dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:backgroundTint="@android:color/transparent"
app:elevation="0dp"
app:itemIconTint="@android:color/white"
app:itemRippleColor="@android:color/white"
app:itemTextColor="@android:color/white"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu_4" />
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/426319.html
