android 自定义Toast

来源:互联网 发布:四柱预测软件 编辑:程序博客网 时间:2024/06/16 09:08

1.很久没有写博客,从今天爱商天天 最少一篇博客。

2.今天看到一个自定义的Toast  把他写成博客。

主要方法

package com.wudl.customtoasts;import android.content.Context;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;import android.widget.Toast;public class CustomToasts {private Context mycontext;public CustomToasts(Context context) {super();mycontext = context;}public void CreateToasts(String message, LayoutInflater inflater) {// 加载容器View inflate = inflater.inflate(R.layout.toasts, null);TextView tv = (TextView) inflate.findViewById(R.id.txt);tv.setText(message);// 设置ToastToast toast = new Toast(mycontext);toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);toast.setDuration(Toast.LENGTH_SHORT);toast.setView(inflate);toast.show();}}

源代码下载地址为,http://download.csdn.net/detail/helloworld_i_android/9522150

0 0
原创粉丝点击