问题描述
我用的是 NotificationCompat.Builder
通过Android的版本,以显示我的通知,并使用自定义布局的通知。
自定义布局正常工作的的Android 3.0及以上(API等级11),但不要在API级别10或更低的出现。我对2.3和2.2模拟器测试它。
I use the NotificationCompat.Builder
to display my notification through android versions and use a custom layout for the notification.
The custom layout works fine on Android 3 and up (API Level 11), but don't show up on API Level 10 or lower. I tested it on 2.3 and 2.2 in the Emulator.
这是我的code:
Builder builder = new NotificationCompat.Builder(getApplicationContext());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);
contentView.setTextViewText(R.id.notTitle, getResources().getString(R.string.streamPlaying));
contentView.setTextViewText(R.id.notText, StartActivity.streamName + " " + getResources().getString(R.string.playing));
builder
.setContentTitle(getResources().getString(R.string.streamPlaying))
.setContentText(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setSmallIcon(R.drawable.stat_icon)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setWhen(0)
.setTicker(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setContent(contentView);
not = builder.build();
很基本的。布局文件是正确的,它在相同的android.com通知教程,以确保我没有犯了一个错误在那里。 ;)
请记住:做工精细在3.0及以上,但不是为2.3低。
really basic. The layout file is correct, its the same as in the notification tutorial on android.com, to make sure I didn't make a mistake in there. ;)
Remember: Working fine on 3.0 and up, but not at 2.3 and lower.
推荐答案
这可能是在支持库中的错误 - 看到的。
This may be a bug in the support library - see this issue.
您可能要解决它通过直接应用的内容查看:
You may have to work around it by applying the contentView directly:
not.contentView = contentView;
这篇关于自定义通知布局没有在Android 2.3或更低的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!