首页 > 移动平台 > 详细

Android Toast

时间:2015-01-08 19:43:35      阅读:206      评论:0      收藏:0      [点我收藏+]
    /* a toast with style white (white background and black text, ...) */
    public static Toast showToastBackgroundWhite(Context context, CharSequence text) {
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        toastLayout.setBackgroundResource(R.drawable.background_round_white_half_transparent2);
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTextColor(Color.BLACK);
        toastTV.setTextSize(40);
        toastTV.setTypeface(null, Typeface.BOLD);
        toastTV.setShadowLayer(0, 0, 0, 0);
        toast.show();
        return toast;
    }
    
    /* a toast with style by default (black background and white text, ...) */
    public static Toast showToast(Context context, CharSequence text) {
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        toastLayout.setBackgroundResource(R.drawable.background_round_black);
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTextSize(40);
        toastTV.setTypeface(null, Typeface.BOLD);
        toast.show();
        return toast;
    }

如果使用白色背景,默认的 Toast 效果是会给字体加阴影的,但在白色背景下非常难看。默认的黑色背景加白色带阴影字体。所以用白色背景时,需要去掉阴影。

 

Toast 显示时候会一个接一个显示,所以可能会造成延时。所以显示后一个 Toast 时应该把前面的取消。做法就是调用 cancel() 方法。

 

Android Toast

原文:http://www.cnblogs.com/davesuen/p/4211655.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!