我是新手Android开发者。我想知道是否可以通过编程方式绘制一个图标放在通知栏中?如果我们希望该图标显示一些动态文本,例如电池电量怎么办?
如果有人有代码示例,那就太好了。谢谢。
我是新手Android开发者。我想知道是否可以通过编程方式绘制一个图标放在通知栏中?如果我们希望该图标显示一些动态文本,例如电池电量怎么办?
如果有人有代码示例,那就太好了。谢谢。
在需要通知的位置调用该函数。
public void notification(String name) {
final int id = 2;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.fbc;
CharSequence tickerText = "facebook";
long when = System.currentTimeMillis();
Notification checkin_notification = new Notification(icon, tickerText,
when);
Context context = getApplicationContext();
CharSequence contentTitle = "You are name is"+ name;
CharSequence contentText = "Do You want to Check-in ?? ";
Intent notificationIntent = new Intent(context, LoginTab.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
checkin_notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
checkin_notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(id, checkin_notification);
}
你看过LevelListDrawable了吗?
http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html