欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程自定義Notification實(shí)例分析

 更新時(shí)間:2015年12月30日 15:14:29   作者:傅榮康  
這篇文章主要介紹了Android編程自定義Notification的用法,結(jié)合實(shí)例形式簡單分析了自定義Notification的具體功能與實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程自定義Notification的用法。分享給大家供大家參考,具體如下:

Notification是一種讓你的應(yīng)用程序在不使用Activity的情況下警示用戶,Notification是看不見的程序組件警示用戶有需要注意的事件發(fā)生的最好途徑。

作為UI部分,Notification對(duì)移動(dòng)設(shè)備來說是最適合不過的了。用戶可能隨時(shí)都帶著手機(jī)在身邊。一般來說,用戶會(huì)在后臺(tái)打開幾個(gè)程序,但不會(huì)注意它們。在這樣的情形下,當(dāng)發(fā)生需要注意的事件時(shí),能夠通知用戶是很重要的。

Notification由NotificationManger統(tǒng)一管理,目前包含的能力有:

❑創(chuàng)建一個(gè)狀態(tài)條圖標(biāo)。

❑在擴(kuò)展的狀態(tài)條窗口中顯示額外的信息(和啟動(dòng)一個(gè)Intent)。

❑閃燈或LED。

❑電話震動(dòng)。

❑發(fā)出聽得見的警告聲(鈴聲,保存的聲音文件)。

自定義Notification效果圖:

 

自定義的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <TextView
 android:id="@+id/tv_rv"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="haha"
 />
<ProgressBar
 style="@android:style/Widget.ProgressBar.Horizontal"
 android:id="@+id/pb_rv"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
</LinearLayout>

創(chuàng)建Notification:

public class CustomNotificationActivity extends Activity {
  NotificationManager notificationManager;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //獲取到系統(tǒng)的notificationManager
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  }
  public void click(View view ){
    //實(shí)例化一個(gè)notification
     String tickerText = "IP號(hào)碼 設(shè)置完畢";
     long when = System.currentTimeMillis();
     Notification notification = new Notification(R.drawable.icon, tickerText, when);
     //不能手動(dòng)清理
     //notification.flags= Notification.FLAG_NO_CLEAR;
     //添加音樂
     //notification.sound = Uri.parse("/sdcard/haha.mp3");
     //設(shè)置用戶點(diǎn)擊notification的動(dòng)作
     // pendingIntent 延期的意圖
     Intent intent = new Intent(this,Bactivity.class);
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
     notification.contentIntent = pendingIntent;
     //自定義界面
     RemoteViews rv = new RemoteViews(getPackageName(), R.layout.noti_layout);
     rv.setTextViewText(R.id.tv_rv, "我是自定義的 notification");
     rv.setProgressBar(R.id.pb_rv, 80, 20, false);
     notification.contentView = rv;
     //把定義的notification 傳遞給 notificationmanager
     notificationManager.notify(0, notification);
  }
}

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論