最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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è)置在通知欄的消息圖標
 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ù)唯一的標識該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 ViewPager實現(xiàn)自動無限輪播和下方向?qū)A點

    android ViewPager實現(xiàn)自動無限輪播和下方向?qū)A點

    本篇文章主要介紹了android ViewPager實現(xiàn)自動輪播和下方向?qū)A點,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-02-02
  • Android的activity學(xué)習(xí)筆記

    Android的activity學(xué)習(xí)筆記

    這篇文章主要整理了Android的activity學(xué)習(xí)筆記,總共有八大亮點,推薦給大家,需要的朋友可以參考下
    2015-09-09
  • 關(guān)于Android多渠道打包的進階知識

    關(guān)于Android多渠道打包的進階知識

    前一篇文章主要介紹了關(guān)于Android程序的多渠道打包方法,這一篇文章介紹了多渠道打包的進階知識,還不會的同學(xué)快進來學(xué)習(xí)下吧,建議收藏以防迷路
    2021-08-08
  • Python的異常概念介紹以及處理

    Python的異常概念介紹以及處理

    本篇文章給大家分享了關(guān)于Python異常的相關(guān)概念知識點以及處理方法,對此有需要的朋友趕快學(xué)習(xí)下吧。
    2018-03-03
  • 一款非常簡單酷炫的LoadingView動畫效果

    一款非常簡單酷炫的LoadingView動畫效果

    這篇文章主要為大家詳細介紹了一款非常簡單酷炫的LoadingView動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android?DataBinding類關(guān)系深入探究

    Android?DataBinding類關(guān)系深入探究

    看了谷歌官方文章確實寫的太簡略了,甚至看完之后有很多地方還不知道怎么回事兒或者怎么用,那么接下來我將通過文章全面介紹一下DataBinding類關(guān)系
    2022-11-11
  • Android仿微信右上角點擊加號彈出PopupWindow

    Android仿微信右上角點擊加號彈出PopupWindow

    這篇文章主要為大家詳細介紹了Android仿微信右上角點擊加號彈出PopupWindow,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Android編程實現(xiàn)提取網(wǎng)址鏈接的方法

    Android編程實現(xiàn)提取網(wǎng)址鏈接的方法

    這篇文章主要介紹了Android編程實現(xiàn)提取網(wǎng)址鏈接的方法,涉及Android針對字符串的正則匹配操作相關(guān)技巧,需要的朋友可以參考下
    2016-10-10
  • Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程分析

    Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程分析

    這篇文章主要介紹了Android6.0開發(fā)中屏幕旋轉(zhuǎn)原理與流程,結(jié)合實例形式詳細分析了Android6.0屏幕旋轉(zhuǎn)的原理與相關(guān)實現(xiàn)流程,并附帶了Android動態(tài)開啟與禁用屏幕旋轉(zhuǎn)的實現(xiàn)方法,需要的朋友可以參考下
    2017-11-11
  • Flutter持久化存儲之數(shù)據(jù)庫存儲(sqflite)詳解

    Flutter持久化存儲之數(shù)據(jù)庫存儲(sqflite)詳解

    這篇文章主要給大家介紹了關(guān)于Flutter持久化存儲之數(shù)據(jù)庫存儲的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03

最新評論

苏尼特右旗| 元朗区| 南靖县| 涿州市| 西昌市| 和政县| 宁武县| 体育| 商城县| 宁德市| 大化| 寿光市| 朝阳县| 和平区| 太仆寺旗| 大港区| 城步| 花莲县| 南皮县| 浦县| 盈江县| 三门峡市| 广州市| 四子王旗| 荔浦县| 平遥县| 易门县| 溧阳市| 达日县| 长岭县| 万宁市| 平和县| 宣汉县| 延边| 安吉县| 岑巩县| 长治市| 修文县| 桃园市| 太康县| 蓝山县|