Как программно добавить представление в уведомление (добавить в RemoveViews) при использовании настраиваемого уведомления - PullRequest
0 голосов
/ 03 июля 2019

Я хочу добавить представление программно к удаленным представлениям.remoteViews имеет собственный метод для представления, например setText и т. д., не может найти метод для добавления представления к remoteViews

Я хочу это

RemoteViews contentView = new 
RemoteViews(BaseApplication.getContext().getPackageName(), 
R.layout.view_notification);
contentView.addView(new TextView(getContext()));

1 Ответ

0 голосов
/ 03 июля 2019

вы можете использовать пользовательский вид, подобный этому

создать уведомление_view.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:padding="10dp" >
<ImageView
    android:src="@mipmap/ic_launcher"
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="10dp" />
<TextView
    android:textSize="13dp"
    android:textColor="#000"
    android:text="Testing"
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/icon"
    />
<TextView
    android:textSize="13dp"
    android:textColor="#000"
    android:text="Testing is awecome"
    android:id="@+id/desc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/icon"
    android:layout_below="@id/title"
     />
</RelativeLayout>

и в коде

RemoteViews customview = new RemoteViews(getPackageName(), R.layout.custom_push);
customview.setImageViewResource(R.id.icon, R.mipmap.ic_launcher);
customview.setTextViewText(R.id.title, "Notification title");
customview.setTextViewText(R.id.dex, "Notification Description");

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon).setContent(customview);

Notification notification = mBuilder.build();
notificationManager.notify(NOTIFICATION_ID, notification);
...