本人还是学习Android方面的新手,每学习一个东西,把学习过程记录下来方便以后查阅,还是挺好的。好了废话不多说.....
看到一个带图片的Toast,的Demo觉得比较新颖,虽然很少看到有人用到项目里。但还是先研究一下:
看了一下,主要是重新定义了一个需要的布局,然后转换成View,在设置到Toast里即可,跟我们自定义对话框一样一样的:
View view = getLayoutInflater().inflate(R.layout.toast, null);
TextView textview = (TextView) view.findViewById(R.id.textview);
textview.setText("这里是Toast显示的\n提示信息......");
Toast toast = new Toast(this);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
在下面是布局这个Toast布局文件代码:
<?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="match_parent"
android:layout_margin="10dp"
android:background="#555"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
下面是效果: