Toast Android 11定制

问题描述

在Android 11中Toast.setView()已过时。
我现在想知道是否可以在不使用setView()的情况下获得类似结果,例如自定义字体,背景颜色,拐角半径等。
在下面可以找到我在setView()中使用的当前视图。

<com.google.android.material.card.MaterialCardView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:clickable="false"
android:focusable="false"
app:cardElevation="0dp"
app:cardBackgroundColor="@color/primary_dark"
android:alpha="0.9"
app:cardCornerRadius="@dimen/radius_toast">

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/toast_dark_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="@dimen/height_toast"
        android:gravity="center"
        android:paddingVertical="@dimen/radius_toast"
        android:layout_marginHorizontal="@dimen/radius_toast"
        android:layout_gravity="center_vertical"
        android:fontFamily="@font/playfair_display_regular"
        tools:text="Custom toast text"
        android:textColor="@color/primary"
        android:textSize="@dimen/text_size_regular_14sp" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...