Toast
来源:互联网 发布:2016淘宝不能邮箱注册 编辑:程序博客网 时间:2024/05/16 11:59
Toast是一种提供给用户简洁提示信息的视图,该视图以浮于应用程序之上的形式呈现给用户
Toast提示界面不获取焦点,所以不影响用户的操作
Toast提示就是在不影响用户使用程序的同时,给用户提供某些提示信息
有两个例子就是音量控制和设置信息保存成功
常用方法
Toast.makeText(context, text, duration); // 返回值为Toasttoast.setDuration(duration); // 设置持续时间toast.setGravity(gravity, xOffset, yOffset); // 设置toast位置toast.setText(s); // 设置提示内容toast.show(); // 显示
显示默认Toast
// Toast toast = Toast.makeText(this, "这是一个默认的Toast", 1000); Toast toast = Toast.makeText(this, R.string.app_name, Toast.LENGTH_SHORT); toast.show();
Toast toast = Toast.makeText(this, "改变位置的Toast", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, -50, -100);// 向右向下为正 toast.show();
Toast toast = Toast.makeText(this, "带有图片的Toast", Toast.LENGTH_SHORT); LinearLayout toast_layout = (LinearLayout) toast.getView(); ImageView iv = new ImageView(this); iv.setImageResource(R.drawable.ic_launcher);// toast_layout.addView(iv); toast_layout.addView(iv, 0); // 图片在文字上 index指定为0 toast.show();
完全自定义的Toast
新建一个布局toast_layout.xml
<?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:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="30dip" android:gravity="center" android:text="这个是自定义的Toast" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="内容部分,我们可以随便写" /> </LinearLayout>
LayoutInflater inflater = LayoutInflater.from(this); View toast_view = inflater.inflate(R.layout.toast_layout, null); Toast toast = new Toast(this); toast.setView(toast_view); toast.show();
0 0
- Toast
- Toast
- Toast
- Toast
- Toast
- Toast
- toast
- Toast
- Toast
- toast
- toast
- Toast
- Toast
- toast
- Toast
- Toast
- Toast
- Toast
- js中(function(){…})()立即执行函数写法理解
- java中的IO操作-IO介绍
- UIImageView和UIImage
- 左值和右值
- 使用console在控制台打印如何不输出最后的换行(aardio)
- Toast
- 新手常用git命令
- 解决Eclipse项目部署之Cannot change version of project facet Dynamic Web Module to 3.0?问题
- L2-4. 这是二叉搜索树吗?(区间递归)
- 文本编辑器
- UVA437 The Tower of Babylon
- Codevs 1220 数字三角形
- js 前加感叹号是什么意思?比如 !function(){}(); 答案在这里
- 《深入浅出WPF》学习笔记之三