How to add vertical line to RemoteView for custom Android Notifications?

萝らか妹 提交于 2019-12-30 10:37:27

问题


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?


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/10607097/how-to-add-vertical-line-to-remoteview-for-custom-android-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!