Я реализовал нижний лист, используя нижний лист диалогового окна. Но по умолчанию он имеет эффект затемнения (Scrim). Как удалить или изменить этот эффект затемнения (сетку) на невидимый, чтобы я мог четко видеть другие элементы пользовательского интерфейса.
Вот макет, который я использовал.
фрагмент_нижний_лист_очереди.xml
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout 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 = "wrap_content"
android:background = "@drawable/res_bottom_sheet_shape"
android:orientation = "vertical">
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "6dp">
<ImageView
android:id = "@+id/close"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center_vertical"
android:layout_marginStart = "10dp"
android:layout_marginTop = "8dp"
android:background = "?selectableItemBackgroundBorderless"
android:contentDescription = "@string/image_description"
android:padding = "10dp"
android:src = "@drawable/ic_close" />
<TextView
android:id = "@+id/txt_queue"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_centerVertical = "true"
android:layout_gravity = "center"
android:layout_marginStart = "8dp"
android:layout_marginEnd = "8dp"
android:fontFamily = "@font/quicksand_medium"
android:gravity = "center"
android:text = "@string/queue"
android:textColor = "@color/dark_white"
android:textSize = "18sp" />
<ImageView
android:id = "@+id/option"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentEnd = "true"
android:layout_gravity = "center_vertical"
android:layout_marginTop = "8dp"
android:layout_marginEnd = "8dp"
android:background = "?selectableItemBackgroundBorderless"
android:contentDescription = "@string/image_description"
android:padding = "10dp"
android:src = "@drawable/ic_menu" />
<ImageView
android:id = "@+id/tickoption"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentEnd = "true"
android:layout_gravity = "center_vertical"
android:layout_marginTop = "8dp"
android:layout_marginEnd = "8dp"
android:visibility = "gone"
android:background = "?selectableItemBackgroundBorderless"
android:contentDescription = "@string/image_description"
android:padding = "10dp"
android:src = "@drawable/ic_done_grey_24dp" />
</RelativeLayout>
<View
android:id = "@+id/view"
android:layout_width = "match_parent"
android:layout_height = "1dp"
android:layout_marginTop = "6dp"
android:background = "@color/light_grey" />
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:id = "@+id/queue_empty_text"
android:layout_marginStart = "8dp"
android:layout_marginEnd = "8dp"
android:layout_marginTop = "10dp"
android:layout_marginBottom = "10dp"
android:visibility = "gone"
android:gravity = "center"
android:textSize = "16sp"
android:fontFamily = "@font/quicksand_medium"
android:text = "@string/queue_empty_text"/>
<androidx.recyclerview.widget.RecyclerView
android:id = "@+id/optionRecyclerView"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginStart = "16dp"
android:layout_marginEnd = "16dp"
android:background = "@color/screen_background"
app:layoutManager = "androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior = "android.support.design.widget.BottomSheetBehavior" />
</LinearLayout>
Фрагмент нижнего листа.java
public class BottomSheetFragment extends BottomSheetDialogFragment {
private BottomSheetBehavior mBehavior;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
View view = View.inflate(getContext(), R.layout.fragment_bottom_queue_sheet, null);
activity = getActivity();
dialog.setContentView(view);
mBehavior = BottomSheetBehavior.from((View) view.getParent());
return dialog;
}
С затемненным эффектом (SCRIM)
Когда нижний лист не вызывается
Вы можете изменить Window
флаги и яркость, чтобы добиться этого эффекта.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog dialog = super.onCreateDialog(savedInstanceState);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
return dialog;
}
Теперь, в 2021 году, есть простой способ изменить диммирование. Просто используйте setDimAmount()
в окне диалога:
val dialog = BottomSheetDialog(context)
...
dialog.window?.setDimAmount(0f) // remove any dim