0

如果文本长度超过50 个字符,则在MI/XIAOMI手机的情况下,通知栏上只显示一行,但在其他手机上工作正常

仅供参考:我们已经在使用大文本样式通知

任何解决方法

4

1 回答 1

0

您必须为小米使用自定义通知,这将有助于开发人员拥有过度自定义操作系统的其他手机。尝试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/images"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/titles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_toEndOf="@+id/images"
        android:text="Title"
        android:textColor="@color/colorAccent"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/notvalue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/titles"
        android:layout_below="@+id/titles"
        android:layout_toEndOf="@id/images"
        android:text="Message"
        android:textColor="@color/colorPrimary" />
</RelativeLayout>

通知代码:

 RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.cusnot);
            remoteViews.setTextViewText(R.id.titles, title);
            remoteViews.setTextViewText(R.id.notvalue, message);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());

            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0);
            builder.setContent(remoteViews)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .build();
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(1, builder.build());
于 2017-11-29T11:37:05.980 回答