Android 音乐播放器的开发教程(十)通知栏Notification的使用 ----- 小达

通知栏Notification的使用

        在这一片博客中,小达将自己学习Notification的一些想法和大家分享一哈,学的不是很深,所有有些东西可能解释的不是特别到位,还请各位谅解哈可怜.所谓Notification即 通知,是一种让你的应用程序在不使用Activity的情况下警示用户。它是看不见的程序组件(Broadcast Receiver,Service和不活跃的Activity) 警示用户有需要注意的事件发生的最好途径。后面的一大段一大段是接着前面的项目在继续,大家可以选择性的看一看.

        Notification 是由NotificationManager(系统服务)统一管理的。挂在下拉通知栏上面,就像下图所示,

       上面显示的都是所谓的Notification,今天我们就来一步步的创建,添加按钮响应,再将Notification和我们的播放器联系起来,话不多说,现在就开始咯.
       
       先给Notification创建了个单独的布局文件,当notification被激活的时候,就在通知栏上面显示这个布局文件的样式,

notification_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/notification_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_photo_01">

    <ImageView                                                                                 //显示歌手头像的,,,,,基本没怎么用上,专辑图片不知道怎么弄得出不来
        android:id="@+id/notification_artist_image"
        android:layout_width="64.0dip"
        android:layout_height="64.0dip"
        android:background="#00000000"/>

    <TextView                                                                                    //在通知栏上显示音乐名称的TextView
        android:id="@+id/notification_music_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:layout_marginStart="5.0dp"
        android:layout_toRightOf="@+id/notification_artist_image"
        android:layout_toEndOf="@+id/notification_artist_image"
        android:focusable="true"
        android:textColor="#FFADABFF"
        android:textSize="18sp"
        />
    <TextView<span style="font-family: Arial, Helvetica, sans-serif;">                                                                                   //在通知栏上显示歌手的TextView</span>
        android:id="@+id/notification_music_Artist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/notification_music_title"
        android:layout_alignStart="@+id/notification_music_title"
        android:layout_marginTop="5.0dip"
        android:layout_below="@id/notification_music_title"
        android:textColor="#FFADABFF"
        />

    <ImageButton                                                                                                      //通知栏上的退出按钮
        android:id="@+id/notification_exit_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/notification_exit"
        android:layout_below="@+id/notification_music_title"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ImageButton
        android:id="@+id/notification_next_song_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/next_music_photo"
        android:layout_toLeftOf="@+id/notification_exit_button"
        android:layout_toStartOf="@+id/notification_exit_button"
        />

    <ImageButton
        android:id="@+id/notification_play_button"
        android:layout_toLeftOf="@id/notification_next_song_button"
        android:layout_toStartOf="@id/notification_next_song_button"
        android:layout_width="w
  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值