我只想添加手機圖標到狀態欄,如圖片中所示。 沒有更多,只是這個小圖標應顯示在狀態欄。將狀態欄添加手機圖標(在哪裏刪除狀態欄?)
我該怎麼做? 無論如何,我可以通過調用某些方法來獲取此圖標嗎?或者我應該用任何工具繪製這個圖標?那麼如何添加這個圖標?
編輯: 我終於通過使用此代碼顯示一個通知:
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);
}
最後在哪裏取消?
檢查https://developer.android.com/guide/topics/ui/notifiers/notifications.html。該圖標是通知圖標。 – rhari
退出程序是什麼意思? – mallaudin
當用戶退出第二項活動時,用戶按回家按鈕並通過向左滑動終止應用程序 –