0

I need to add a RelativeLayout with a TextView and a Button in it to top of notifications in status bar.

Is there any way to do that?

Nima Ahmadi
  • 41
  • 1
  • 9

1 Answers1

1

Your XML Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="3dp"
              >
    <ImageView android:id="@+id/image"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="10dp"
              />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#000"
              />
</LinearLayout>

Your Code

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
contentView.setTextViewText(R.id.text, "Hello, this message is in a custom expanded view");
notification.contentView = contentView;


Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.contentIntent = contentIntent;

Sending Notification

mNotificationManager.notify(CUSTOM_VIEW_ID, notification);

Reference :- ftp://ftp.gunadarma.ac.id/android/sdk/sdk_310712/docs/guide/topics/ui/notifiers/notifications.html

Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61