[英]Custom snackbar has a text overlay
I am making a custom snackbar with the following我正在使用以下内容制作自定义小吃店
fun showSnack(view: View, text:String){
val snackbar = Snackbar.make(view, text, Snackbar.LENGTH_LONG)
val snackbarView = snackbar.view
snackbarView.setBackgroundColor(Color.TRANSPARENT)
val inflater = LayoutInflater.from(view.context)
val layout = inflater.inflate(R.layout.custom_snack,null,false)
layout.custom_text.text = text
val slayout = snackbar.view as SnackbarLayout
slayout.addView(layout,0)
snackbar.show()
}
custom_snack.xml: custom_snack.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:layout_margin="2dp"
app:cardBackgroundColor="@color/off_white"
android:theme="@style/Theme.MaterialComponents.Light"
app:cardCornerRadius="16dp"
android:background="@color/transparent"
app:cardElevation="0dp"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:padding="8dp"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/appCompatImageView"
android:layout_width="50dp"
android:layout_height="25dp"
android:src="@drawable/home" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/toast_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sample text"
android:gravity="center"
android:paddingStart="8dp"
android:layout_gravity="center"
tools:ignore="HardcodedText,RtlSymmetry" />
</androidx.appcompat.widget.LinearLayoutCompat>
</com.google.android.material.card.MaterialCardView>
using it like so:像这样使用它:
showSnack(findViewById(android.R.id.content),"Access Granted")
the custom snackbar showsup in the screen but there is a text overlay and I can't figure where it's coming from.屏幕上显示了自定义的快餐栏,但有一个文本覆盖,我不知道它是从哪里来的。 Extra text Extra text Extra text Extra text Extra text Extra text Extra text Extra text
额外文本 额外文本 额外文本 额外文本 额外文本 额外文本 额外文本 额外文本
Your issue is here:你的问题在这里:
val snackbar = Snackbar.make(view, text, Snackbar.LENGTH_LONG)
Use:利用:
val snackbar = Snackbar.make(view, "", Snackbar.LENGTH_LONG)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.