Android自定义下载状态栏
2016-05-12 15:41
513 查看
手机自带的下载状态栏可能觉得有low,那就试试自定义的view吧。
思路:通过
主要代码(下面用到的布局是笔者自己的布局
思路:通过
RemoteViews获取布局,并设置标题等,
NotificationCompat.Builder对象加载布局。
主要代码(下面用到的布局是笔者自己的布局
R.layout.download):
private NotificationCompat.Builder ncb = null; private Notification notification;
//创建 nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); //这里需要设置图片(下载过程中又不会显示),不设置又可能就没法显示自定义的下载布局(亲测)。不知道原因 ncb = (NotificationCompat.Builder) new NotificationCompat.Builder(getBaseContext()) .setSmallIcon(R.mipmap.ic_launcher);
//RemoteViews 获取自定义布局 RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.download); //设置布局中TextView属性,前面的id是布局中TextView的id,后面是要设置的值,布局中的其它空间均有类似的方法 contentView.setTextViewText(R.id.bar_name,"下载进度"); //加载布局 ncb.setContent(contentView); //创建状态栏 notification = ncb.build(); //通知更新状态栏 nm.notify(0, notification);
//下载过程中更新状态栏 RemoteViews contentView = notification.contentView; contentView.setProgressBar(R.id.bar,100,values[0],false); //设置布局中的监听,有两个监听方式:setOnClickFillInIntent(),setOnClickPendingIntent()方法中需要传入intent和pendingIntent参数,前面的id是布局中控件的id contentView.setOnClickPendingIntent(R.id.bar,pendingIntent);
相关文章推荐
- Android中进程管理
- android studio使用svn证书错误
- Android 属性动画 详解
- Android基础--登陆界面,密码的隐藏和显示
- Android 中ListView 嵌套 ListView
- android-如何获得当前正在运行的activity的相关信息
- android应用实现重启系统
- 查看Android应用所需权限(uses-permission)
- Android常用布局各个属性的含义
- Android数据存储之SharedPreferences详解
- Android--LayoutInflater
- Android Camera后台拍照
- Android屏幕适配(一)dp、px、dpi、sp的理解
- Android RecyclerView使用Demo
- Android判断包名和类名是否存在的方法
- android 自定义 PDF view
- android:contentDescription 的用途
- SwipeMenuListView滑动删除
- Android MVP实战
- Android 一些Api说明