我无法获得要显示的自定义布局的通知。如果我使用以下(旧)代码:
notification = new Notification();
notification.icon = R.drawable.icon;
notification.tickerText = currentTickerText;
notification.when = System.currentTimeMillis();
notification.setLatestEventInfo(context, (CharSequence)currentTitle, (CharSequence)"", pendingIntent);
一切都按预期工作,并显示通知。但是,如果我使用以下(新)代码:
contentView = new RemoteViews(context.getPackageName(), R.layout.service_notification);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.title, (CharSequence)currentTitle);
contentView.setTextViewText(R.id.text, (CharSequence)"");
contentView.setViewVisibility(R.id.pgStatus, View.GONE);
notification = new Notification();
notification.tickerText = currentTickerText;
notification.when = System.currentTimeMillis();
notification.contentView = contentView;
notification.contentIntent = pendingIntent;
通知永远不会显示。我也没有收到错误,所以我不确定在哪里寻找问题。这是 service_notification 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:text="This is the title."
style="@style/NotificationTitle" />
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_below="@id/title"
android:text="This is the status"
style="@style/NotificationText" />
<ProgressBar
android:id="@+id/pgStatus"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_toRightOf="@+id/image" />
</RelativeLayout>
另外,如果有什么不同,我会在 Android 2.2 模拟器上运行它。
任何人都知道什么可能是错误的,或者我可以如何去追踪这个问题?我有点不知所措,因为我没有要处理的错误消息。谢谢!