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

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

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

一:先來(lái)效果圖

二:實(shí)現(xiàn)步驟

1.xml布局實(shí)現(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的實(shí)現(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號(hào)過(guò)年喲!";
 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)};
 //待處理意圖對(duì)象
 mIntent = PendingIntent.getActivities(this, 0, intents, 0);
 //消息欄通知對(duì)象
 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è)置默認(rèn)的聲音,此外還可以設(shè)置震動(dòng)(需加入權(quán)限)
 mNotification.defaults = Notification.DEFAULT_SOUND;
 //添加燈光
// mNotification.defaults=Notification.DEFAULT_LIGHTS;
 //不能刪除
 mNotification.flags = Notification.FLAG_NO_CLEAR;
 //設(shè)置下拉時(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ā)送通知
 // 第一個(gè)參數(shù)唯一的標(biāo)識(shí)該Notification,第二個(gè)參數(shù)就是Notification對(duì)象
 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號(hào)過(guò)年喲!" />
</LinearLayout>

5.跳轉(zhuǎn)activity的實(shí)現(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();
 }
}

簡(jiǎn)單粗暴實(shí)用,你值得擁有

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

相關(guān)文章

最新評(píng)論

辰溪县| 广东省| 赣州市| 肥东县| 定西市| 黄大仙区| 佛冈县| 博罗县| 托里县| 临海市| 辽中县| 上思县| 遂昌县| 伊金霍洛旗| 无为县| 行唐县| 历史| 和平县| 丽水市| 琼中| 正蓝旗| 兴海县| 南开区| 罗田县| 银川市| 临汾市| 娄底市| 平罗县| 丹东市| 金门县| 高雄市| 松桃| 凤阳县| 桐庐县| 津市市| 汉寿县| 汕头市| 遂川县| 芜湖市| 三门县| 中山市|