安卓:自定义Toast通知继承默认吐司 [英] Android: Custom Toast Notification Inherit Default Toast
本文介绍了安卓:自定义Toast通知继承默认吐司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有具有图像和文本自定义Toast通知。自定义敬酒工作正常,但是我想知道我怎么做我的自定义敬酒继承默认的祝酒词的外观和感觉?我希望它看起来像漂亮的圆角和边框默认的。
这是我的自定义敬酒的样子。
<?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / toast_layout_root
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:填充=10dp
机器人:背景=#DAAA>
< ImageView的机器人:ID =@ + ID / chatIcon
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginRight =10dp
机器人:SRC =@绘制/ ic_chat/>
< TextView的机器人:ID =@ + ID /文
机器人:文字=@字符串/ unread_message_toast
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:文字颜色=#FFF
/>
< / LinearLayout中>
解决方案
我在应用程序之一使用。改变周围的一些东西,它应该为你工作了。
吐司ImageToast =新吐司(getBaseContext());
的LinearLayout toastLayout =新的LinearLayout(
getBaseContext());
toastLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView的形象=新ImageView的(getBaseContext());
image.setImageResource(R.drawable.easter_egg);
toastLayout.addView(图片);
ImageToast.setView(toastLayout);
ImageToast.setDuration(Toast.LENGTH_SHORT);
ImageToast.show();
I have a custom toast notification which has an image and text. The custom toast works fine however I am wondering how do I make my custom toast inherit the default toasts look and feel? I want it to look like the default one with the nice rounded corners and borders.
This is what my custom toast looks like.
<?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>
解决方案
I use this in one of my apps. Change a few things around and it should work for you too.
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();
这篇关于安卓:自定义Toast通知继承默认吐司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文