Android自定义通知未显示

Android自定义通知未显示,android,android-layout,android-notifications,Android,Android Layout,Android Notifications,我试图在android 11上创建一个自定义通知布局。 通知已创建,但内容为空。 你能告诉我我做错了什么吗 谢谢 应用程序代码: Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificati

我试图在android 11上创建一个自定义通知布局。 通知已创建,但内容为空。 你能告诉我我做错了什么吗

谢谢

应用程序代码:

            Intent notificationIntent = new Intent(this, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                    notificationIntent, 0);

            RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notif_layout);
            Notification notification = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
                    .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                    .setContent(notificationLayout)
                    .setSmallIcon(R.drawable.ic_attestinator)
                    .setContentIntent(pendingIntent)
                    .build();
            startForeground(1, notification);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/notif_layout"
    android:layout_width="fill_parent"
    android:layout_height="64dp">

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_marginStart="8dp"
        android:scaleType="centerCrop"
        android:translationY="16dp"
        tools:srcCompat="@drawable/ic_baseline_av_timer_24" />

    <TextView
        android:id="@+id/notif_timer_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="xx:xx"
        android:textSize="20dp"
        android:translationY="14dp" />

</LinearLayout>
布局:

            Intent notificationIntent = new Intent(this, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                    notificationIntent, 0);

            RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notif_layout);
            Notification notification = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
                    .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                    .setContent(notificationLayout)
                    .setSmallIcon(R.drawable.ic_attestinator)
                    .setContentIntent(pendingIntent)
                    .build();
            startForeground(1, notification);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/notif_layout"
    android:layout_width="fill_parent"
    android:layout_height="64dp">

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_marginStart="8dp"
        android:scaleType="centerCrop"
        android:translationY="16dp"
        tools:srcCompat="@drawable/ic_baseline_av_timer_24" />

    <TextView
        android:id="@+id/notif_timer_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="xx:xx"
        android:textSize="20dp"
        android:translationY="14dp" />

</LinearLayout>

我最终找到了解决方案: 这是一个颜色pb:当我强制文本颜色为android:white时,文本出现了