How to add vertical line to RemoteView for custom Android Notifications?
Asked Answered
G

2

4

I'm struggling to add a vertical line to a custom Android Notification. I've tried adding a view like this to my Relative Layout:

<View
    android:id="@+id/line_vertical"
    android:layout_width="1dip"
    android:layout_height="fill_parent"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@id/image_logo"
    android:background="#0000FF" />

But when I fire the notification, I get the following Exception:
android.app.RemoteServiceException: Bad notification posted from package XXX: Couldn't expand RemoteViews for: StatusBarNotification(package=XXX)

Anybody have any ideas?

Galvanize answered 15/5, 2012 at 18:57 Comment(0)
S
6

You can't inflate just any view in a RemoteView. Change your View to an empty TextView or ImageView.

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

FrameLayout
LinearLayout
RelativeLayout

And the following widget classes:

AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

Descendants of these classes are not supported.

Reference: http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

Surname answered 15/5, 2012 at 18:59 Comment(2)
You da man K-ballo. Using an ImageView worked perfectly. Here's my code: <ImageView android:id="@+id/image_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:contentDescription="@string/app_name" />Galvanize
Thanks for explanation.Stationmaster
I
2
    <LinearLayout
        android:layout_width="1dp"
        android:layout_height="25dp"
        android:layout_gravity="center_vertical"
        android:alpha="0.3"
        android:background="#FFFFFF" />

We have to add like this.

Ivie answered 25/2, 2013 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.