Android之Toast的用法
2011-09-26 09:31
204 查看
Toast是用来向用户展示一些提示性信息,并且该VIEW永远不会获得系统的焦点
一般定义为:Toast.makeText(MyClass.this,"note info",Toast.LENGTH_SHORT).show();
也可以在Tost中显示出自定义的VIEW,如下所示展示出图片和文字
自定义的 一个显示Toast的方法
protected void showToast() {
// create the view
View view = inflateView(R.layout.incoming_message_panel);
// set the text in the view
TextView tv = (TextView)view.findViewById(R.id.message);
tv.setText("khtx. meet u for dinner. cul8r");
// show the toast
Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
incoming_message_panel的定义如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/toast_frame">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_thumb_2"
/>
<TextView
android:id="@+id/message"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
/>
</LinearLayout>
</FrameLayout>
toast_frame图片如下所示
一般定义为:Toast.makeText(MyClass.this,"note info",Toast.LENGTH_SHORT).show();
也可以在Tost中显示出自定义的VIEW,如下所示展示出图片和文字
自定义的 一个显示Toast的方法
protected void showToast() {
// create the view
View view = inflateView(R.layout.incoming_message_panel);
// set the text in the view
TextView tv = (TextView)view.findViewById(R.id.message);
tv.setText("khtx. meet u for dinner. cul8r");
// show the toast
Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
incoming_message_panel的定义如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/toast_frame">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_thumb_2"
/>
<TextView
android:id="@+id/message"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
/>
</LinearLayout>
</FrameLayout>
toast_frame图片如下所示
相关文章推荐
- Android开发之Toast的用法
- Android:Toast的用法
- Android的Dialog、Toast和Snackbar基本用法与优化
- 学Android---Toast用法简介
- android-Toast的用法
- Android中Toast的用法简介
- Android Toast 总结(五种用法)
- Android中Toast的几种用法
- 【android】Toast 的用法
- Android中Toast的用法简介
- Android中Toast的多种用法
- Android中Toast的用法简介
- Android Toast 的用法
- 【android】Toast用法总结
- Android toast的几种用法
- android toast用法总结(一)
- android中Toast 的简单用法
- Android中Toast的用法简介
- android 信息提示 Toast.makeText 用法
- Android开发之——消息模式Toast.makeText的常见用法