唯一的解决方案是创建我自己的 RemoteView,如下所示:
首先,自定义布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/list_selector_background">
<ImageView
android:id="@+id/big_icon"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:scaleType="fitCenter"
/>
<TextView
android:id="@+id/title"
android:text="sometitlestringfromresources"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignBottom="@+id/big_icon"
android:layout_toRightOf="@+id/big_icon"
android:layout_marginLeft="15dp"/>
<ImageView
android:id="@+id/big_picture"
android:layout_width="match_parent"
android:layout_height="192dp"
android:layout_marginTop="64dp"
android:scaleType="fitCenter" //This scale will show your picture without crop
/>
以及 RemoteView 实现:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
RemoteViews views;
views = new RemoteViews(getPackageName(), R.layout.custom_notification);
views.setImageViewBitmap(R.id.big_picture, bitmap);
views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.your_24x24dp_brand_icon));
views.setTextViewText(R.id.title, message);
myNotification.bigContentView = views;
}
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(randomInt, myNotification);
其中 myNotification 是您的通知构建器,而 randomInt 是我自己的无重叠通知实现(检查这是否不是您需要替换通知或生成多个通知)。
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);
就是这样。也许有点脏,但它有效。我会把这个错误留给谷歌,如果我收到一些回复,我会更新这个。