2016-11-19 85 views
0

我只想添加手機圖標到狀態欄,如圖片中所示。 沒有更多,只是這個小圖標應顯示在狀態欄。將狀態欄添加手機圖標(在哪裏刪除狀態欄?)

我該怎麼做? 無論如何,我可以通過調用某些方法來獲取此圖標嗎?或者我應該用任何工具繪製這個圖標?那麼如何添加這個圖標?

enter image description here

編輯: 我終於通過使用此代碼顯示一個通知:

 NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         .setSmallIcon(R.drawable.ic_phone_white_36dp) 
         .setContentTitle("My notification") 
         .setContentText("Hello World!"); 
// Creates an explicit intent for an Activity in your app 
     Intent resultIntent = new Intent(this, SecondActivity.class); 


     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
// Adds the back stack for the Intent (but not the Intent itself) 
     stackBuilder.addParentStack(SecondActivity.class); 
// Adds the Intent that starts the Activity to the top of the stack 
     stackBuilder.addNextIntent(resultIntent); 
     PendingIntent resultPendingIntent = 
       stackBuilder.getPendingIntent(
         0, 
         PendingIntent.FLAG_UPDATE_CURRENT 
       ); 
     mBuilder.setContentIntent(resultPendingIntent); 
     mNotificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
// mId allows you to update the notification later on. 
     mNotificationManager.notify(2, mBuilder.build()); 

但我用我的應用二的活動。現在移除是個問題。我想在用戶退出程序時刪除此通知,以便在何處取消通知?

mNotificationManager.cancel(2); 

我試過的onDestroy:它不工作,它沒有被刪除時,用戶退出程序。

@Override 
    protected void onDestroy() { 
     super.onDestroy(); // Always call the superclass method first 

     mNotificationManager.cancel(2); 
    } 

我試過在onStop:它正在工作,但當用戶傳遞另一個應用程序時,此通知被刪除。我不想這樣。

@Override 
    protected void onStop() { 
     super.onStop(); // Always call the superclass method first 

     mNotificationManager.cancel(2); 
    } 

最後在哪裏取消?

+1

檢查https://developer.android.com/guide/topics/ui/notifiers/notifications.html。該圖標是通知圖標。 – rhari

+0

退出程序是什麼意思? – mallaudin

+0

當用戶退出第二項活動時,用戶按回家按鈕並通過向左滑動終止應用程序 –

回答

0

這是一個通知圖標,收到通知時顯示。在創建通知時附有通知。您可以在發送通知時添加任何類型的圖標。在您的狀態欄中,通知會顯示附帶的phone圖標。你可以找到更多關於通知here的信息。

+0

我編輯了我的問題。你能再讀一遍嗎? –