Android(安卓)Notification and icon issue
16lz
2021-01-26
notification icon must be 24x24 dp for optimal solution on most devices.
see
http://developer.android.com/design/style/iconography.html#notification
or create the following notification sizes:
72x72px size in drawable-xxhdpi
48x48px in drawable-xhdpi
36x36px in drawable-hdpi
24x24px in drawable-mdpi
18x18px in drawable-ldpi
以上尺寸是给状态栏和提示滚动信息用图标尺寸。 下拉以后的大图标的尺寸就比较随意了。
下面是代码实现,用的是系统默认的布局。 旧写法:
NotificationManagernotificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);Notificationnotification=newNotification(icon,message,when);Stringtitle=context.getString(R.string.title);IntentnotificationIntent=newIntent(context,LaunchActivity.class);//setintentsoitdoesnotstartanewactivitynotificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);PendingIntentintent=PendingIntent.getActivity(context,0,notificationIntent,0);//SetthedetailsofNotificationnotification.setLatestEventInfo(context,title,message,intent);notification.tickerText=message;notification.defaults=Notification.DEFAULT_SOUND;notification.flags|=Notification.FLAG_AUTO_CANCEL;notification.icon=R.drawable.ticker_icon;BitmapFactory.Optionsopt=newBitmapFactory.Options();opt.inPurgeable=true;opt.inInputShareable=true;InputStreamis=context.getResources().openRawResource(R.drawable.large_icon);Bitmapbitmap=BitmapFactory.decodeStream(is,null,opt);notification.largeIcon=bitmap;//Thecustomofnotification/*RemoteViewscontentView=newRemoteViews(context.getPackageName(),R.layout.notification);contentView.setImageViewResource(R.id.notification_image,R.drawable.large_icon);contentView.setTextViewText(R.id.notification_title,title);contentView.setTextViewText(R.id.notification_text,message);notification.contentView=contentView;*///showNotificationnotificationManager.notify(id,notification);
更多相关文章
- 仿照探探卡片滑动
- Android刷新加载框架详解
- Android代码优化----PullToRefresh+universal-image-loader实现
- Android(安卓)package名要区分大小写
- 浅析Android(安卓)Camera开发中的三个尺寸和三种变形 (贡献一个
- android iphone手机分辨率尺寸比例整理
- Android(安卓)下拉列表框(spinner)
- 下拉刷新SwipeRefreshLayout源码
- Android中更改SQLite数据库中的数据后,刷新ListView。