自定义简单的Toast,可自行修改文字、图片、样式
2016-05-27 10:41
609 查看
/**
*
* @param context
* @param text 直接传字符串
* @param resId 图片ID
*/
public static void showTwo(Context context, String text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的,如若不设置将会是系统默认Toast位置
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
/**
* 传字段ID
* @param context
* @param text 文字ID
* @param resId 图片ID
*/
public static void showTwo(Context context, int text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
TextView textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
源码下载地址:(初次发文,多多关注)
http://download.csdn.net/detail/qq_31850557/9532987
*
* @param context
* @param text 直接传字符串
* @param resId 图片ID
*/
public static void showTwo(Context context, String text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的,如若不设置将会是系统默认Toast位置
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
/**
* 传字段ID
* @param context
* @param text 文字ID
* @param resId 图片ID
*/
public static void showTwo(Context context, int text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
TextView textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
源码下载地址:(初次发文,多多关注)
http://download.csdn.net/detail/qq_31850557/9532987
相关文章推荐
- 修改选择文件文本框及按钮样式
- CSS3 三个比较蛋疼的关键字
- 纯css实现未知尺寸图片在DIV中垂直水平居中(超简单)
- 10-CSS格式化排版
- CSS基础
- 【Web动画】CSS3 3D 行星运转 && 浏览器渲染原理
- 排行榜妙用——CSS计数器
- 浏览器默认样式
- CSS动画--页面特效
- css hack
- css 加号 选择器
- css3 -- 背景图处理
- CSS3 animation
- css3 -- 多列
- 用css布局页脚,固定页脚始终在最下面
- CSS居中问题
- css3 -- 文本
- css 的@media print控制打印
- 一些元素居中的方法css的设置
- 如何让两个元素的相对位置不变,设置css