我有一个自定义的 Toast 通知,其中包含图像和文本。自定义 toast 工作正常,但我想知道如何使我的自定义 toast 继承默认 toast 的外观和感觉?我希望它看起来像默认的那样,具有漂亮的圆角和边框。
这就是我定制的吐司的样子。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA">
<ImageView android:id="@+id/chatIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/ic_chat"/>
<TextView android:id="@+id/text"
android:text="@string/unread_message_toast"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
我在我的一个应用程序中使用它。改变一些事情,它也应该对你有用。
Toast ImageToast = new Toast(getBaseContext());
LinearLayout toastLayout = new LinearLayout(
getBaseContext());
toastLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView image = new ImageView(getBaseContext());
image.setImageResource(R.drawable.easter_egg);
toastLayout.addView(image);
ImageToast.setView(toastLayout);
ImageToast.setDuration(Toast.LENGTH_SHORT);
ImageToast.show();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)