Android Tutorial

(avery) #1
Android Tutorial 423

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="31dp"
android:textColor="#000" />
<TextView
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#f00" />



This particular example is similar to the default notification but
does not contain an icon. The setLatestEventInfo() method is
normally used to assign the text to the default layout. In this
example, we use our custom layout instead. The Intent still needs
to be assigned, though, as follows:

Intent toLaunch = new Intent
(SimpleNotificationsActivity.this,
SimpleNotificationsActivity.class);
PendingIntent intentBack = PendingIntent.getActivity
(SimpleNotificationsActivity.this, 0, toLaunch, 0);
notify.contentIntent = intentBack;
notifier.notify(NOTIFY_5, notify);


The end result looks something like Figure.

Custom notification showing with just
two lines of text.

Using a custom notification layout can
provide better control over the information
on the expanded status bar. Additionally, it
can help differentiate your application’s
notifications from other applications by
Free download pdf