1. 現象android
在Android4.0以上系統中,彈出通知欄消息時圖標顯示不全,以下圖:app
2. 問題來源:ide
Android 4.0以上版本頂部導航欄StatusBar的實現類PhoneStatusBar的bug:函數
在com.android.systemui.SystemUIService的onCreate()中:ui
在此處選擇實例化statusbar(手機通知欄)仍是systembar(平板通知欄):url
在PhoneStatusBar.start() => StatusBar.start()時調用自身的虛函數addIcon()(即調用PhoneStatusBar的addIcon()函數)中實例化頂部導航欄Icon的view(PhoneStatusBarView)的時候,利用常數設置了縮放比例,並無根據圖片的實際大小縮放。spa
3. 解決方案orm
(1)初步:反射xml
public Notification(Context context, int icon, CharSequence tickerText, long when, CharSequence contentTitle, CharSequence contentText, Intent contentIntent) {}中的icon既是通知欄中提示的小icon,又是通知欄下拉菜單中的大icon,通知欄提示小icon沒法修改,可是通知欄下拉菜單的大icon能夠在組建RemoteViews時進行修改:blog
先在建立Notification時設置icon爲小icon,在建立RemoteViews以後反射com.android.internal.R$id的icon值,從而調用Notification的contentView.setImageViewResource(id_icon, R.drawable.icon)重置大icon。
(2)進階:android-support-v4.jar中的NotificationCompat.Builder
NotificationCompat.Builder支持設置smallicon(通知欄提示的小icon)和largeIcon(通知欄下拉菜單中的大icon)。NotificationCompat.Builder根據SDK版本的調用不一樣的實現類進行兼容。