通知未显示完整布局

Notification was not showing full layout

我在 android 自定义通知中工作,为此我设计了自定义布局。但是当我收到通知时,此布局的某些部分未显示。 please check the screen shot of Notification

请有人建议我如何为 Notifications.how 使用自定义布局 我的代码如下所示。

我实际的自定义布局代码是

<?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="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:orientation="vertical">

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="12dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/notificationHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/startedVideoStreaming"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#000" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1.5dp"
        android:background="@color/silvercolor"></LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:orientation="horizontal"
        android:weightSum="4">

        <TextView
            android:id="@+id/pauseId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center"
            android:text="pause"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#000" />

        <TextView
            android:id="@+id/stopLiveId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center"
            android:text="StopLive"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#000" />
    </LinearLayout>
</LinearLayout>

我的 android 代码是

 private void showForegroundNotification() {
        RemoteViews contentLayout = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
        contentLayout.setTextViewText(R.id.notificationHeader, getString(R.string.startedVideoStreaming));
        contentLayout.setTextViewText(R.id.pauseId, "Pause");
        contentLayout.setTextViewText(R.id.stopLiveId, "StopLive");

        final NotificationManager notifyManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Intent to call our activity from background.
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        // The PendingIntent to launch our activity if the user selects this notification.
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        Notification notification = null;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            notification = new Notification.Builder(getApplicationContext())
                    .setContent(contentLayout)
                    .setContentIntent(contentIntent)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setWhen(System.currentTimeMillis())
                    .setOngoing(true)
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setLights(Color.WHITE, 500, 500)
                    .build();
        }

        notification.flags = Notification.FLAG_NO_CLEAR;
        notifyManager.notify(STREAMER_NOTIFICATION_ID, notification);
    }

请有人帮助摆脱这种情况

使用当前代码,从您的代码中删除以下行

.setContent(contentLayout)

设置标志时添加上面的行

notification.bigContentView = contentLayout;
notification.flags = Notification.FLAG_NO_CLEAR;