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

android源码分析 android toast使用详解 toast自定义

时间:2014-06-22 13:54:32      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:android   style   ext   color   get   使用   

在安卓开发过程中,toast使我们经常使用的一个类,当我们需要向用户传达一些信息,但是不需要和用户交互时,该方式就是一种十分恰当的途径。

我们习惯了这样使用toast:Toast.makeText(Context context, String info, int duration).show();该方法是

系统为我们提供的一个方便的创建toast对象的静态方法,其内部依然是调用toast的相关方法完成。下面

就从其源码对该类的实现做一个分析

在toast类中,最重要的用于显示该toast的show方法调用了service.enqueueToast(pkg, tn, mDuration);也就是说

系统为我们维持了一个toast队列,这也是为什么两个toast不会同时显示的原因,该方法将一个toast入队,显示则由系统维持显示的时机。

 private static INotificationManager sService;


    static private INotificationManager getService() {
        if (sService != null) {
            return sService;
        }
        sService = INotificationManager.Stub.asInterface(ServiceManager.getService("notification"));
        return sService;
    }
该服务sService就是系统用于维护toast的服务。

在toast内部又一个静态私有类TN,该类是toast的主要实现,该类完成了toast视图的创建,等等


fa

android源码分析 android toast使用详解 toast自定义,布布扣,bubuko.com

android源码分析 android toast使用详解 toast自定义

标签:android   style   ext   color   get   使用   

原文地址:http://blog.csdn.net/hackuncle/article/details/32102293

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