我想在完成一些後臺工作後在Android頂部顯示這種消息。 如何顯示此類通知? 謝謝..如何在Android中顯示頂部欄消息
4
A
回答
4
這看起來像一個Notification
的股票文本,假定該截圖是在屏幕的頂部。您可以通過setTicker()
on your NotificationCompat.Builder
將其添加到Notification
。但是,請注意,從API Level 21(Android 5.0)開始,不再顯示股票行情文本。另外請注意,幾秒鐘後,股票行情文本會自動消失。
+0
是的,setTicker()是方法,它的工作原理。謝謝 – 2014-10-28 14:48:58
0
您可以使用SYSTEM_ALERT_WINDOW,它始終在上面顯示消息,無論您的應用程序是前臺還是後臺。
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER|Gravity.TOP;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.addView(view, params);
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
1
建設的通知,並使用setTicker(看DOC there):
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event)
.setContentTitle(eventTitle)
.setContentText(eventLocation)
.setContentIntent(viewPendingIntent)
.setTicker("Your message");
2
這是通知警告,這可以從服務,活動,碎片,廣播接收器等開始。 .. 檢查此鏈接:http://developer.android.com/guide/topics/ui/notifiers/notifications.html
這個例子是從谷歌開發複製:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());
祝你好運!
相關問題
- 1. 如何在頂部的chrome擴展中顯示消息?
- 2. 如何在窗體頂部顯示錯誤消息
- 3. android - 如何顯示消息
- 4. NSAlert在操作表頂部顯示「不再顯示此消息」
- 5. ViewController中的頂部欄ios swift顯示前一個頂部欄
- 6. 如何顯示unread消息欄
- 7. 如何在全屏顯示uiimage時顯示導航欄頂部和工具欄?
- 8. 在操作欄頂部顯示視圖
- 9. 如何在chartjs中的每個欄的頂部顯示bar值
- 10. Android - 底部的工具欄 - 如何在頂部顯示邊框線
- 11. 在UITableView的頂部顯示一條消息
- 12. ActionBar(Sherlock)在頂部顯示帶有消息數量的圖標
- 13. 顯示在屏幕頂部的span消息
- 14. 如何顯示在窗口的標題欄的頂部菜單
- 15. 顯示消息點擊窗口頂部沒有滾動到頂部
- 16. 如何在secondActivity中顯示Toast消息?
- 17. 如何在logcat中顯示長消息
- 18. 如何在Maven中顯示消息
- 19. jQuery是否有一個插件來顯示「消息欄」,如屏幕頂部的Twitter「錯誤密碼」欄?
- 20. 如何模擬StackOverflow在Rails中用於flash [:notice]和flash [:error]消息的頂部站點消息欄
- 21. 如何在每個頁面上顯示消息欄
- 22. 如何在outlook 2007消息窗口中顯示自定義信息欄?
- 23. 其他應用程序頂部的消息顯示
- 24. 如何顯示Toast消息?
- 25. PHPmailer如何顯示消息
- 26. Laravel調試欄不顯示消息
- 27. 如何在Android中顯示非模態臨時彈出消息?
- 28. 如何在android中的onPause()之前顯示Toast消息?
- 29. 如何在Android中單擊禁用按鈕時顯示消息?
- 30. 如何在Android中啓動活動時顯示日誌消息
使用自定義的吐司,請參考這個http://stackoverflow.com/questions/11288475/custom-toast-in-android-a-simple-example – 2014-10-28 10:42:22
什麼阻止你使用TextView對齊父對象的頂部,左邊複合可繪製在裏面?通常它會是INVISIBLE,然後你只有在需要的時候才能看到它。 – 2014-10-28 10:47:57