I have changed the width to MATCH_PARENT even if I use custom layout,it still doesn't work. And I want it's bottom gap is 0, so I set layout.bottom = 0, it also doesn't work. how to resolve it? My device is an AndroidPad.
snackbar in MainActivity
val view: View = findViewById(android.R.id.content)
var inflater = LayoutInflater.from(this)
val customView: View = inflater.inflate(R.layout.custom_snackbar, null)
snackbar = Snackbar.make(view, "", Snackbar.LENGTH_LONG)
snackbar?.setBackgroundTint(ContextCompat.getColor(this, R.color.primary))
val layout = snackbar?.view as Snackbar.SnackbarLayout
val textView: TextView = customView.findViewById(R.id.snackbar_text)
val layoutParams = layout.layoutParams
layout.bottom = 0
textView.text = message
layoutParams.width = CoordinatorLayout.LayoutParams.MATCH_PARENT//change to LinearLayout or FrameLayout get the same effect
layout.removeAllViews()
layout.addView(customView)
snackbar?.show()
custom_snackbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_snackbar">
<TextView
android:id="@+id/snackbar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"/>
</LinearLayout>


Please add below code to your layout :
for further more information please check : link