码迷,mamicode.com
首页 > 移动开发 > 详细

android Toasts

时间:2014-05-08 04:19:04      阅读:357      评论:0      收藏:0      [点我收藏+]

标签:android   toast   

1.基础

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();
当然也可以将方法连起来而不是保持一个Toast对象:

Toast.makeText(context, text, duration).show();
2.放置位置

toast.setGravity(Gravity.TOP|Gravity.LEFT, x, y);
可以通过setGravity方法来改变toast的默认显示位置

3.自定义Toast

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
                               (ViewGroup) findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

android Toasts,布布扣,bubuko.com

android Toasts

标签:android   toast   

原文地址:http://blog.csdn.net/androidstudio/article/details/25249019

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!