android开发(二十) Toast五种特效详解
来源:互联网 发布:地牢探测器JS手机版 编辑:程序博客网 时间:2024/05/19 23:24
Toast是Android中用来显示显示信息的一种机制,和Dialog不一样的是,
Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失。
一 默认效果:
代码:
Toast.makeText(getApplicationContext(), "默认Toast样式",Toast.LENGTH_SHORT).show();
二 自定义显示位置效果:
代码:
toast = Toast.makeText(getApplicationContext(),"自定义位置Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
三 带图片效果:
代码
toast = Toast.makeText(getApplicationContext(),"带图片的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.icon);
toastView.addView(imageCodeProject, 0);
toast.show();
四 完全自定义效果:
代码
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.llToast));
ImageView image = (ImageView) layout.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
五 其他线程:
代码:
new Thread(new Runnable() {
public void run() {
showToast();
}
}).start();
- android开发(二十) Toast五种特效详解
- Android 开发笔记: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详解
- Android特效 五种Toast详解
- sort的用法
- shell中set参数解释
- 怎么查看老婆的通话记录?QQ1622863529
- 我想知道我老婆在哪里怎么定位她的手机?QQ1622863529
- JDK框架简析--java.lang包中的基础类库、基础数据类型
- android开发(二十) Toast五种特效详解
- ie6 bug 遗漏
- 老公总是背着我偷偷打电话给别的女人,怎么查通话记录?QQ1622863529
- 解决Incorrect integer value: '' for column 'id' at row 1的方法
- POJ3681[Finding the Rectangle]【枚举+限界】(轉)
- HTML 中有用的字符实体
- Linux下解析配置文件
- 6、数据库锁机制
- linux鸟哥私房菜学习笔记之三-shell