Lea*_*ros 18 layout notifications android
我用它NotificationCompat.Builder
来通过Android版本显示我的通知,并使用自定义布局进行通知.
自定义布局在Android 3及更高版本(API级别11)上运行良好,但不会出现在API级别10或更低级别.我在模拟器中测试了2.3和2.2.
继承我的代码:
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();
Run Code Online (Sandbox Code Playgroud)
真的很基本.布局文件是正确的,它与android.com上的通知教程相同,以确保我没有在那里犯错.;)
记住:3.0及以上工作正常,但不是2.3及更低.
Ugg*_*dle 38
这可能是支持库中的错误 - 请参阅此问题.
您可能需要通过直接应用contentView来解决它:
not.contentView = contentView;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8260 次 |
最近记录: |