Как получить общую картину моего пользовательского уведомления по всей ширине уведомления, сохраняя при этом системные украшения Android? - PullRequest
0 голосов
/ 22 февраля 2019

У меня есть приложение с 19 (KitKat) в качестве минимального SDK.

Мне нужно уведомление, которое действует как смесь BigPictureStyle и BigTextStyle .Для этого я использую удаленные виды вместе с DecoratedCustomViewStyle , чтобы получить желаемый эффект, но в результате большое изображение не занимает всю ширину, и вместо этого я получаю это:

the big image doesn't take the whole width

Проблема не в том, какой размер изображения я использую, потому что удаление DecoratedCustomViewStyle из построителя уведомлений устраняет проблему ширины, но без нее я неЯ не могу получить все системные украшения (см. изображение ниже), и требуется, чтобы они тоже были.

Image size ok, but no system decorations

Я также нашел Accengage'sшаблоны уведомлений , где у них есть этот стиль под названием BigTextBigPicture , который именно то, что мне нужно, но, хотя они предоставляют файлы макетов, я не могу заставить его работать на телефонах с Nougat и выше, так как я получаютот же результат, который я получил, удалив DecoratedCustomViewStyle, поэтому без системных декораций.

Вот построитель уведомлений:

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(),
        Constants.CHANNEL_ID)
        .setSmallIcon(R.drawable.my_app_logo)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setCustomContentView(notificationLayout)
        .setCustomBigContentView(notificationLayoutExpanded)
        .setStyle(new NotificationCompat.DecoratedCustomViewStyle());

Вот макет уведомлений_большой

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="256dp"
    android:orientation="vertical">
        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:fadingEdge="horizontal"
            android:maxLines="2"
            style="@style/TextAppearance.Compat.Notification.Title"
            android:text="@string/notification_test_title"/>

        <TextView
            android:id="@+id/msg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:fadingEdge="horizontal"
            android:maxLines="6"
            style="@style/TextAppearance.Compat.Notification"
            android:text="@string/notification_test_msg"/>

    <ImageView
        android:layout_marginStart="2dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/test_cute_kirby"
        android:scaleType="fitXY"/>

</LinearLayout>
...