自定义Toast
来源:互联网 发布:2016年就业数据 编辑:程序博客网 时间:2024/06/04 22:46
转载自:http://blog.csdn.net/yongxinzhenxi/article/details/25069415
自定义Toast
public class ToastView { private static ToastView toastView; private Toast toast; private ToastView() { } public static ToastView createToastConfig(){ if (toastView==null){ toastView=new ToastView(); } return toastView; } public void ToastShow(Context context, ViewGroup root, String sString){ View view= LayoutInflater.from(context).inflate(R.layout.toast_style,root); TextView text= (TextView) view.findViewById(R.id.toast); text.setText(sString); toast=new Toast(context); toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL,0,100); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.show(); }}Toast的样式设置:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout" android:layout_width="match_parent" android:background="@drawable/toast_bg" android:layout_height="match_parent"> <TextView android:id="@+id/toast" android:layout_width="200dip" android:layout_height="30dip" android:gravity="center" android:textColor="#ffffff" android:textSize="18sp" /></LinearLayout>背景设置:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="20dip"/> <solid android:color="#00ff00"/></shape>调用:
private ToastView tostView;tostView=ToastView.createToastConfig();tostView.ToastShow(MainActivity.this,(ViewGroup) findViewById(R.id.toast_layout),"你好哇,李银河!!!");
0 0
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义toast
- 自定义toast
- 自定义Toast
- 自定义toast
- 自定义Toast
- 自定义Toast
- 自定义Toast
- Toast自定义
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义toast
- 自定义Toast
- 如何递归创建Ttee的Node
- 将数组中值为0的项去掉,将不为0的值存入一个新的数组,生成新数组
- spring MVC的实现原理
- linux文件I/O编程
- XMl解析的几种方式
- 自定义Toast
- Edittext中输入@符号关联联系人及快速索引
- 程序员到大数据人才 只需这几步
- 两个int类型的数组合并为新的数组
- XC2440开发板编写BSP文件
- ThreadLocal + Filter 处理事务
- 将一个给定的整型数组转置输出
- Velocity教程
- 51NOD 1127 最短的包含字符串(尺取法)