Android开发新手。我想知道是否有可能以编程方式绘制一个图标放入通知栏?如果我们希望图标显示电池级别的动态文本怎么办?
如果有人有代码示例,那就太好了。感谢。
答案 0 :(得分:4)
调用我们想要通知的功能。
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);
}
答案 1 :(得分:1)
答案 2 :(得分:1)
你看过LevelListDrawable吗?
http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html