2

I am trying to create custom notification in my android application. I am using following code

Custom layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:background="@drawable/notification_background"
        android:clickable="true" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/ic_action_test" />
    </LinearLayout>
</LinearLayout>

This is how I am creating my notification

RemoteViews contentView = new RemoteViews(activity.getPackageName(), R.layout.notification);

            Notification noti = new NotificationCompat.Builder(activity)

                    .setSmallIcon(R.drawable.ic_launcher)
                    .build();
            noti.contentView = contentView;
            // Hide the notification after its selected
            noti.flags |= Notification.FLAG_NO_CLEAR;

            notificationManager.notify(0, noti);

The notification is created, however it does not cover the full height on the notification bar even though I am using fill_parent for height attribute.

Can anybody tell me what is wrong here?

Ashwani K
  • 7,880
  • 19
  • 63
  • 102

1 Answers1

1

it's too late but helped me, wish it could help you too. make a background image in xml or png which is transparent (if you want you can color it), and the height of background image must be longer than the notification height.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/tran"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:background="@drawable/notification_background"
        android:clickable="true" >
        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/ic_action_test" />
    </LinearLayout>
</LinearLayout>

tran.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent"/>
    <size android:width="400dp" android:height="400dp"/>
</shape>
user3840019
  • 155
  • 1
  • 10