【问题标题】:Unable to set all text in textview in Notification Manger RemoteVIew无法在 Notification Manger RemoteVIew 的 textview 中设置所有文本
【发布时间】:2016-05-18 10:54:04
【问题描述】:
public void CustomNotification(String title, String adress) {

                 RemoteViews remoteViews = new RemoteViews(getPackageName(),
                         R.layout.customnotification);        
                     Intent intent = new Intent(this, MainActivity.class);

                 PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                         PendingIntent.FLAG_UPDATE_CURRENT);
                 Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                 NotificationCompat.Builder builder = new NotificationCompat.Builder(this)

                         .setSmallIcon(R.drawable.ic_launcher)

                         .setTicker("Custom Notification Ticker")
                         .setPriority(Notification.PRIORITY_MAX)
                         .setAutoCancel(true)

                         .setContentIntent(pIntent)
                         .setSound(alarmSound)

                         .setContent(remoteViews);

                 remoteViews.setTextViewText(R.id.title, title);
                 remoteViews.setTextViewText(R.id.text, adress);        
                 NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        
                 notificationmanager.notify(0, builder.build());

             }






 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
<!-- try this-->
            android:layout_height="100dp"
        android:padding="8dp" >

        <ImageView
            android:id="@+id/thumbnail"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="8dp"
            android:background="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/thumbnail"
            android:layout_toRightOf="@+id/thumbnail"
            android:text="Heading"
            android:textStyle="bold" />
                     <TextView
            android:id="@+id/text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/title"
            android:layout_marginTop="1dip"
            android:layout_toRightOf="@+id/thumbnail" />

    </RelativeLayout>

我正在动态打印 text-view 中的文本,但是当文本增加时,即使我手动增加 textView 的高度,文本也会在 text-view 中部分可见。然后它也没有显示所有文本。

请给我建议。我该如何解决?

【问题讨论】:

    标签: android


    【解决方案1】:

    在通知生成器上使用大样式文本而不是小文本。

    Notification notif = new Notification.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .setStyle(new Notification.BigTextStyle()
             .bigText(aVeryLongString))
         .build();
    

    【讨论】:

    • 尝试设置时出现错误
    • 我用过这个它不工作请告诉我解决方案如果你知道
    • 在您的 xml 文件中,而不是包装相对布局的内容,为您的通知设置您想要的高度。
    猜你喜欢
    • 2020-07-01
    • 2020-03-01
    • 2018-11-13
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    相关资源
    最近更新 更多