我正试图在我的活动中设置一个自定义SnackBar,虽然它没有覆盖我所有的屏幕,但这一切都很好.我的问题是什么呢?
这是我的Snackbar配置:
private fun configureSnackbarWarning() {
val snackbar = Snackbar.make(binding.root, "", Snackbar.LENGTH_LONG)
snackbar.view.setBackgroundColor(Color.TRANSPARENT)
val customSnackView: View = layoutInflater.inflate(R.layout.layout_movements_snackbar, null)
val snackbarLayout = snackbar.view as Snackbar.SnackbarLayout
snackbarLayout.setPadding(0, 0, 0, 0)
snackbarLayout.minimumWidth = ViewGroup.LayoutParams.MATCH_PARENT
// Add the custom view to the Snackbar's layout
snackbarLayout.addView(customSnackView)
snackbar.show()
}
这是我的Snackbar XML(Layout_Moves_Snackbar):
<?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="wrap_content"
android:background="@color/default_background">
<TextView
android:id="@+id/txt_warning_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/snackbar_movements_bg_warning"
android:drawableStart="@drawable/ic_no_movement_warning"
android:drawablePadding="16dp"
android:fontFamily="@font/poppins_bold"
android:padding="16dp"
android:text="@string/pagination_warning"
android:textColor="@color/snackbar_text_warning"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
我已经try 将Snackbar填充和边距设置为0,但仍然没有好的结果