在我的 app
我正在建立一个自定义 notification
用big view
关于 150dp
.
layout
下面给出
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imagenotileft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imagenotileft" />
<View
android:id="@+id/view"
android:layout_width="365dp"
android:layout_height="@dimen/dp_2"
android:layout_marginTop="@dimen/dp_23"
android:layout_centerHorizontal="true"
android:layout_below="@+id/title"
android:background="@color/comunica_app_light_grey" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view"
android:layout_toRightOf="@+id/imagenotileft" />
<ImageView
android:id="@+id/imagenotiright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dp" />
</RelativeLayout>
View
组件导致 app
创建时崩溃 notification
函数被调用。code
没有问题部分原因是它在没有 View
的情况下完美膨胀组件。
错误期间的日志如下。
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1
12-21 10:27:36.504 1701-1701/? E/StatusBar: couldn't inflate view for notification edu.uoc.app.comunica.dev/0x0
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.view.View
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.view.View
Caused by: android.view.InflateException: Binary XML file line #0: Class not allowed to be inflated android.view.View
at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:683)
at android.view.LayoutInflater.createView(LayoutInflater.java:634)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:700)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.widget.RemoteViews.inflateView(RemoteViews.java:3198)
at android.widget.RemoteViews.apply(RemoteViews.java:3162)
at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:1667)
at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:2171)
at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1407)
at com.android.systemui.statusbar.BaseStatusBar$7$2.run(BaseStatusBar.java:634)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
12-21 10:27:36.528 29283-29283/edu.uoc.app.comunica.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.uoc.app.comunica.dev, PID: 29283
android.app.RemoteServiceException: Bad notification posted from package edu.uoc.app.comunica.dev: Couldn't expand RemoteViews for: StatusBarNotification(pkg=edu.uoc.app.comunica.dev user=UserHandle{0} id=0 tag=null key=0|edu.uoc.app.comunica.dev|0|null|10115: Notification(pri=0 contentView=edu.uoc.app.comunica.dev/0x7f0c002a vibrate=null sound=null tick defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
我无法从日志中找出是什么原因造成的。
请提供解决方案。
最佳答案
你已经为这两个 View 添加了这个id
android:id="@+id/title"
并且下面的id没有分配给任何view
@+id/send_date
这可能是问题所在
关于android - 无法在自定义通知中包含简单 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47919052/