1

I making notification of this kind in Android but somehow getting the following type of exception. Please help me solve the issue. I have used the height 64dp for the rootview and this is the custom view for the notification. This custom view is then set using setContent in the notificationCompat builder.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:layout_marginLeft="@dimen/marginBig"
    android:layout_marginRight="@dimen/marginBig">

    <ImageView
        android:id="@+id/mg_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="12dp"
        android:src="@drawable/mg_round_image"/>

    <TextView
        android:id="@+id/mg_emergency"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/mg_logo"
        android:layout_toRightOf="@id/mg_logo"
        android:text="@string/mg_emergency_card"
        android:textAppearance="@style/P1.Medium.Vermillion"/>

    <TextView
        android:id="@+id/call_ambulance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/mg_emergency"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="@dimen/marginBig"
        android:clickable="true"
        android:text="@string/call_ambulance"
        android:textAllCaps="true"
        android:textAppearance="@style/P3.Bold.Vermillion"/>

    <TextView
        android:id="@+id/vertical_line"
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/mg_logo"
        android:layout_alignTop="@id/call_ambulance"
        android:layout_toLeftOf="@id/call_ambulance"
        android:background="@color/divider_line">
    </TextView>

    <TextView
        android:id="@+id/emergency_contact_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/mg_emergency"
        android:layout_below="@id/mg_emergency"
        android:layout_marginRight="8dp"
        android:layout_toLeftOf="@id/vertical_line"
        android:lines="2"
        android:text="@string/my_emergency_contact"
        android:textAppearance="@style/P2.Regular.Grey2"
        tools:text="My Emergency Contact Manisha- 0987654321"/>

    <TextView
        android:id="@+id/horizontal_line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/vertical_line"
        android:background="@color/divider_line">
    </TextView>

    <TextView
        android:id="@+id/send_alert_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/call_ambulance"
        android:layout_below="@id/call_ambulance"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:text="@string/send_alerts"
        android:textAllCaps="true"
        android:textAppearance="@style/P3.Bold.Primary"/>
</RelativeLayout>
Raghav Sharma
  • 780
  • 10
  • 18

1 Answers1

1

The answer to this question is silly....I just changed the margin for the rootview(relative layout) from @dimen/marginBig to hard code(16dp) and it worked fine. @M_AWADI answer in this post android - Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification helped me achieve.

Raghav Sharma
  • 780
  • 10
  • 18
  • 1
    Thank you so much for this! Hard coding the values on the root view (LinearLayout for me) fixed it. – CamHart Sep 19 '18 at 00:28