亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android之開發(fā)消息通知欄

 更新時間:2017年04月10日 09:34:31   作者:瞳瞳色丶輕煙的博客  
本文主要介紹了Android開發(fā)消息通知欄的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧

一:先來效果圖

二:實現(xiàn)步驟

1.xml布局實現(xiàn)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="edu.feicui.notification.MainActivity">
 <Button
 android:id="@+id/btn_create"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="發(fā)送通知"
 android:textSize="25sp" />
</LinearLayout>

2.activity的實現(xiàn)

package edu.feicui.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RemoteViews;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
 /**
 * 通知欄Notification
 */
 private NotificationManager mManager;
 private Notification mNotification;
 private PendingIntent mIntent;
 private String cll;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 cll = "今年27號過年喲!";
 ButterKnife.bind(this);
 }
 @Override
 public void onContentChanged() {
 super.onContentChanged();
 init();
 }
 private void init() {
 //初始化通知欄管理者
 mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

 //意圖數(shù)組
 Intent[] intents = {new Intent(this, NotificationAcitivity.class)};
 //待處理意圖對象
 mIntent = PendingIntent.getActivities(this, 0, intents, 0);
 //消息欄通知對象
 mNotification = new Notification();
 }
 @OnClick(R.id.btn_create)
 public void create() {
 //設(shè)置在通知欄的消息圖標(biāo)
 mNotification.icon = R.mipmap.logo_new;
 //設(shè)置在通知欄的信息內(nèi)容
 mNotification.tickerText = "重大消息";
 //設(shè)置默認的聲音,此外還可以設(shè)置震動(需加入權(quán)限)
 mNotification.defaults = Notification.DEFAULT_SOUND;
 //添加燈光
// mNotification.defaults=Notification.DEFAULT_LIGHTS;
 //不能刪除
 mNotification.flags = Notification.FLAG_NO_CLEAR;
 //設(shè)置下拉時的顯示布局
 RemoteViews convertView = new RemoteViews(getPackageName(), R.layout.layout_content);
 convertView.setImageViewResource(R.id.img, R.mipmap.logo_new);
 convertView.setTextViewText(R.id.txt, cll);
 mNotification.contentView = convertView;
 mNotification.contentIntent = mIntent;
 //發(fā)送通知
 // 第一個參數(shù)唯一的標(biāo)識該Notification,第二個參數(shù)就是Notification對象
 mManager.notify(1, mNotification);
 }
}

3.AndroidManifest添加權(quán)限

<uses-permission android:name="android.permission.VIBRATE"/>

4.跳轉(zhuǎn)界面的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:gravity="center"
 android:orientation="vertical">
 <TextView
 android:id="@+id/txt"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textColor="#ff0000"
 android:textSize="20dp"
 android:text="今年27號過年喲!" />
</LinearLayout>

5.跳轉(zhuǎn)activity的實現(xiàn)

package edu.feicui.notification;
import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;
import android.widget.TextView;
/**
 * Created by Administrator on 2017-1-20.
 */
public class NotificationAcitivity extends Activity {
 private NotificationManager mManager;
 private int index = 2;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_notification);
 //初始化通知欄管理者
 mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 index = 2;
 mManager.cancelAll();
 }
}

簡單粗暴實用,你值得擁有

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

  • Android編程實現(xiàn)設(shè)置按鈕背景透明與半透明及圖片背景透明的方法

    Android編程實現(xiàn)設(shè)置按鈕背景透明與半透明及圖片背景透明的方法

    這篇文章主要介紹了Android編程實現(xiàn)設(shè)置按鈕背景透明與半透明及圖片背景透明的方法,結(jié)合實例形式較為詳細的分析了Button及ImageButton的背景屬性設(shè)置技巧,非常簡單實用,需要的朋友可以參考下
    2015-12-12
  • Android數(shù)據(jù)加密之Des加密

    Android數(shù)據(jù)加密之Des加密

    這篇文章主要為大家詳細介紹了Android數(shù)據(jù)加密之Des加密,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解OpenGL Shader彩虹條紋效果的實現(xiàn)

    詳解OpenGL Shader彩虹條紋效果的實現(xiàn)

    這篇文章主要為大家介紹了如何通過OpenGL Shader實現(xiàn)彩虹條紋效果,最后的效果和圖片處理軟件colorow中的彩虹效果濾鏡相似,需要的可以參考一下
    2022-02-02
  • Android Handler中的休眠喚醒實現(xiàn)詳解

    Android Handler中的休眠喚醒實現(xiàn)詳解

    這篇文章主要為大家介紹了Android Handler中的休眠喚醒實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android AnalogClock簡單使用方法實例

    Android AnalogClock簡單使用方法實例

    這篇文章主要介紹了Android AnalogClock簡單使用方法,結(jié)合實例形式簡單分析了AnalogClock的布局調(diào)用技巧,需要的朋友可以參考下
    2016-01-01
  • RN在Android打包發(fā)布App(詳解)

    RN在Android打包發(fā)布App(詳解)

    下面小編就為大家?guī)硪黄猂N在Android打包發(fā)布App(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Android實現(xiàn)動態(tài)向Gallery中添加圖片及倒影與3D效果示例

    Android實現(xiàn)動態(tài)向Gallery中添加圖片及倒影與3D效果示例

    這篇文章主要介紹了Android實現(xiàn)動態(tài)向Gallery中添加圖片及倒影與3D效果的方法,涉及Android針對圖片的加載、顯示、翻轉(zhuǎn)、倒影等相關(guān)特效功能實現(xiàn)技巧
    2016-08-08
  • Android中LayoutAnimal的使用方法詳解

    Android中LayoutAnimal的使用方法詳解

    這篇文章給大家講講酷炫的動畫成員LayoutAnimal,文章通過一個實例給大家詳細介紹了Android中LayoutAnimal的使用方法,感興趣的小伙伴可以自己動手試一試
    2023-09-09
  • Android不同版本兼容性適配方法教程

    Android不同版本兼容性適配方法教程

    這篇文章主要介紹了Android不同版本兼容性適配方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-11-11
  • Android使用Opengl錄像時添加水印

    Android使用Opengl錄像時添加水印

    這篇文章主要為大家詳細介紹了Android使用Opengl錄像時添加水印,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04

最新評論