阅读更多

 Toast用于向用户显示一些帮助/提示。下面我做了5中效果,来说明Toast的强大,定义一个属于你自己的Toast。

1.默认效果

代码

Toast.makeText(getApplicationContext(), "默认Toast样式",
Toast.LENGTH_SHORT).show();

 

2.自定义显示位置效果

代码

toast = Toast.makeText(getApplicationContext(),
"自定义位置Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();

 

3.带图片效果

 

代码

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();

 

4.完全自定义效果

代码

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();

 

5.其他线程

代码

new Thread(new Runnable() {
public void run() {
showToast();
}
}).start();

更多相关文章

  1. android位移动画的两种实现方式
  2. ListView 实现阻尼回弹效果 并去除边缘阴影
  3. Android仿IOS 仿微信 右滑关闭Activity(附源码)
  4. LayoutInflater的inflate方法使用
  5. android下载系统版本步骤(通过SecureCRT)
  6. Android(安卓)国际化 语言相关 和 打包 多渠道配置
  7. android 画图------类似跑马灯的效果
  8. Android(安卓)Studio快捷键(自用)
  9. Android中创建倒影效果的工具类

随机推荐

  1. ubuntu创建wifi热点(android可识别)亲测
  2. [置顶] Android 操作SQLite数据库(初步)-在
  3. 【Android】Android UI 开发_问答_3
  4. Artifactory 4 PRO /HA 版 搭建Android镜
  5. Google Android应用开发03 Android SDK介
  6. Android深入浅出之Zygote
  7. 实例教程十一:访问通信录中的联系人和添加
  8. 初遇Android——跨进程使用Service
  9. 【Android开发学习15】Android OpenGL ES
  10. Activity生命周期的回调,你应该知道得更多