将状态栏添加手机图标(在哪里删除状态栏?)

问题描述:

我只想添加手机图标到状态栏,如图片中所示。 没有更多,只是这个小图标应显示在状态栏。将状态栏添加手机图标(在哪里删除状态栏?)

我该怎么做? 无论如何,我可以通过调用某些方法来获取此图标吗?或者我应该用任何工具绘制这个图标?那么如何添加这个图标?

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

当用户退出第二项活动时,用户按回家按钮并通过向左滑动终止应用程序 –

你可以从这里https://material.io/icons/#ic_phone

下载图标,然后将其添加在你的应用程序,你必须创建一个通知https://developer.android.com/guide/topics/ui/notifiers/notifications.html

+0

好吧,但是如何将此图标添加到状态栏? –

这是一个通知图标,收到通知时显示。在创建通知时附有通知。您可以在发送通知时添加任何类型的图标。在您的状态栏中,通知会显示附带的phone图标。你可以找到更多关于通知here的信息。

+0

我编辑了我的问题。你能再读一遍吗? –