我需要show()扩展的FAB并基于 bool 值hide()。我在扩展BottomSheetDialogFragment的 Bottom Sheet 中使用它。问题是,它在 Bottom Sheet 处于展开状态时有效,但在默认情况下在工作表打开状态下不起作用。我还观察到了一个奇怪的行为-默认情况下,FAB在工作表打开时显示,一秒钟后消失。我不确定是什么原因导致了这种现象。我尝试默认情况下隐藏FAB,但是它不起作用。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <androidx.core.widget.NestedScrollView
        android:layout_gravity="top"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            tools:context=".ui.attendance.employee.selection.EmployeeSelectionBottomSheet">

            <TextView
                android:id="@+id/copy_to_emp_title"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_width="wrap_content"
                android:paddingBottom="16dp"
                android:text="@string/copy_to"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />


            <androidx.constraintlayout.widget.ConstraintLayout
                android:background="@color/palegrey"
                android:id="@+id/copy_to_emp_search_cc"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_width="match_parent"
                android:paddingBottom="16dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/copy_to_emp_title"
                tools:visibility="visible">

                <com.google.android.material.textfield.TextInputLayout
                    style="@style/TextInputLayoutAppearance"
                    android:hint="@string/enter_chip_txt"
                    android:id="@+id/copy_to_emp_search_til"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_width="0dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">


                    <HorizontalScrollView
                        android:id="@+id/copy_to_emp_hsv"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"
                        android:scrollbars="none">

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            tools:layout_editor_absoluteX="8dp"
                            tools:layout_editor_absoluteY="503dp">


                            <com.google.android.material.chip.ChipGroup
                                android:id="@+id/copy_to_emp_cg"
                                android:layout_height="wrap_content"
                                android:layout_width="wrap_content"
                                app:layout_constraintBottom_toBottomOf="@+id/copy_to_emp_et"
                                app:layout_constraintEnd_toStartOf="@+id/copy_to_emp_et"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="@+id/copy_to_emp_et" />


                            <com.google.android.material.textfield.TextInputEditText
                                android:hint="@string/enter_chip_txt"
                                android:id="@+id/copy_to_emp_et"
                                android:layout_height="wrap_content"
                                android:layout_width="wrap_content"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toEndOf="@+id/copy_to_emp_cg"
                                app:layout_constraintTop_toTopOf="parent" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </HorizontalScrollView>
                </com.google.android.material.textfield.TextInputLayout>


                <TextView
                    style="@style/Body14Left4SemiBold"
                    android:id="@+id/copy_to_emp_filter"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/filter"
                    app:layout_constraintBottom_toBottomOf="@+id/copy_to_emp_filter_icon"
                    app:layout_constraintStart_toStartOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toTopOf="@+id/copy_to_emp_filter_icon" />

                <ImageView
                    android:id="@+id/copy_to_emp_filter_icon"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:layout_width="wrap_content"
                    android:padding="3dp"
                    android:src="@{isFilterViewExpanded?@drawable/ic_arrow_up:@drawable/ic_arrow_down}"
                    app:layout_constraintEnd_toEndOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_search_til"
                    tools:src="@drawable/ic_arrow_down" />

                <TextView
                    style="@style/Body14Left2Regular"
                    android:id="@+id/copy_to_emp_category_label"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:layout_width="wrap_content"
                    android:text="@string/category"
                    app:layout_constraintStart_toStartOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_filter" />

                <TextView
                    style="@style/Body14Left2Regular"
                    android:background="@drawable/rounded_rect_white_5"
                    android:id="@+id/copy_to_emp_category"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginTop="8dp"
                    android:layout_width="0dp"
                    android:padding="8dp"
                    android:text="@string/select_your_filter_category"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_category_label" />

                <TextView
                    style="@style/Body14Left2Regular"
                    android:id="@+id/copy_to_emp_sub_category_label"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:layout_width="wrap_content"
                    android:text="@string/sub_category"
                    app:layout_constraintStart_toStartOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_category" />

                <TextView
                    style="@style/Body14Left2Regular"
                    android:background="@drawable/rounded_rect_white_5"
                    android:id="@+id/copy_to_emp_sub_category"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_width="0dp"
                    android:padding="8dp"
                    android:text="@string/select_your_filter_sub_category"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="@+id/copy_to_emp_search_til"
                    app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_sub_category_label" />


                <com.google.android.material.button.MaterialButton
                    android:id="@+id/copy_to_add_filter_btn"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:layout_width="wrap_content"
                    android:text="Add Filter"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.5"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/copy_to_emp_sub_category" />

                <androidx.constraintlayout.widget.Group
                    android:id="@+id/copy_to_emp_group"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:visibility="@{isFilterViewExpanded?View.VISIBLE:View.GONE}"
                    app:constraint_referenced_ids="copy_to_emp_sub_category,copy_to_emp_sub_category_label,copy_to_emp_category,copy_to_emp_category_label, copy_to_add_filter_btn"
                    tools:visibility="visible" />


            </androidx.constraintlayout.widget.ConstraintLayout>


            <com.google.android.material.chip.ChipGroup
                android:id="@+id/copy_to_selected_filter_cg"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_width="0dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/copy_to_emp_search_cc" />

            <TextView
                android:id="@+id/copy_to_emp_count_tv"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="24dp"
                android:layout_width="wrap_content"
                android:text="All Employee (264)"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/copy_to_selected_filter_cg" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/copy_to_rv"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                android:layout_marginTop="16dp"
                android:layout_width="match_parent"
                android:minHeight="60dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/copy_to_emp_count_tv" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:backgroundTint="@color/blueberry"
        android:id="@+id/copy_to_apply_changes_btn"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_width="wrap_content"
        android:text="Apply changes"
        android:textColor="@color/whitetwo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

最佳答案

  • 将ExtendedFloatingActionButton更改为FloatingActionButton
  • 添加

  • />
      </com.google.android.material.circularreveal.CircularRevealFrameLayout>
    
  • fab.setOnClickListener {
    fab.isExpanded =!fab.isExpanded
    }
  • 就是这样
  • 关于android - 如何使扩展的 float 操作按钮显示在 Bottom Sheet 的底部?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61078180/

    10-12 01:38