自定义Toast实现各种炫酷效果
2017-07-05 13:36
225 查看
在开发App的时候,提示信息必不可少。如何实现自定义的炫酷效果的Toast的呢。
下面是一个自定义的Toast效果,根据自己的需求实现各种炫酷效果。
下载地址:http://download.csdn.net/download/gl_mine_csdn/9889339 点击打开链接
下面是一个自定义的Toast效果,根据自己的需求实现各种炫酷效果。
下载地址:http://download.csdn.net/download/gl_mine_csdn/9889339 点击打开链接
public class MyToastUtils { private static Toast mToast; private static int mToastViewId = -1;//自定义提示的视图id //开始显示toast public static void show(Context context, String msg) { if (TextUtils.isEmpty(msg)) return; int duration; if (msg.length() > 10) { duration = Toast.LENGTH_LONG; //如果字符串比较长,那么显示的时间也长一些。 } else { duration = Toast.LENGTH_SHORT; } if (mToast == null) { mToast = Toast.makeText(context, msg, duration); if (mToastViewId != -1) { LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflate.inflate(mToastViewId, null); TextView toast = (TextView) v.findViewById(R.id.toast);//r.id.toast 则为自己自定义的view布局的item toast.setText(message); mToast.setView(v); } } else //r.id.toast 则为自己自定义的view布局的item ((TextView) mToast.getView().findViewById(R.id.toast)).setText(message); mToast.setDuration(duration); } //居中显示 mToast.setGravity(Gravity.CENTER,0,0); mToast.show(); } //自定义布局 public static void setmToastViewId(int mToastViewId) { ToastUtils.mToastViewId = mToastViewId; } } xml 文件 r.layout.toast <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:textSize="14sp" android:textColor="#fff" android:background="#000"/> 使用方式: 第一步 初始化 (设置了布局) MyToastUtils.setmToastViewId(R.layout.toast); 第二步 使用方法 ToastUtils.show(context, "msg");
相关文章推荐
- 制作自定义WmlListAdapter来实现Mobile.List控件的各种效果
- [Wap] 制作自定义WmlListAdapter来实现Mobile.List控件的各种效果
- [Wap] 制作自定义WmlListAdapter来实现Mobile.List控件的各种效果
- 自定义Toast,实现不错的效果
- Android属性动画上手实现各种动画效果,自定义动画,抛物线等
- Android UI设计之<七>自定义Dialog,实现各种风格效果的对话框
- android从源码解析并实现各种Toast效果合集
- Android实现自定义字体跑马灯(炫酷效果)以及导航菜单字体炫酷展示
- Android学习笔记_42_各种图形的炫酷效果的实现和使用
- 自定义ViwePager实现各种动画效果
- android从源码解析并实现各种Toast效果合集
- Android UI设计系列之自定义Dialog实现各种风格的对话框效果(7)
- 通过自定义.xml文件实现各种效果的SeekBar
- [Wap] 制作自定义WmlListAdapter来实现Mobile.List控件的各种效果
- android 自定义菜单 使用PopupWindow实现菜单的各种效果
- Android学习笔记_42_各种图形的炫酷效果的实现和使用
- [Wap] 制作自定义WmlListAdapter来实现Mobile.List控件的各种效果
- Android自定义PopupWindow实现炫酷的IOS对话框效果
- android学习笔记---59_各种图形的使用介绍,android炫酷效果的实现
- xq_navbar简单实现依赖于jQuery自定义快捷的炫酷导航条效果