0

我需要在状态栏中的通知顶部添加一个带有 TextView 和 Button 的 RelativeLayout。

有没有办法做到这一点?

4

1 回答 1

1

你的 XML 布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="3dp"
              >
    <ImageView android:id="@+id/image"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="10dp"
              />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#000"
              />
</LinearLayout>

你的代码

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
contentView.setTextViewText(R.id.text, "Hello, this message is in a custom expanded view");
notification.contentView = contentView;


Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.contentIntent = contentIntent;

发送通知

mNotificationManager.notify(CUSTOM_VIEW_ID, notification);

参考:- ftp://ftp.gunadarma.ac.id/android/sdk/sdk_310712/docs/guide/topics/ui/notifiers/notifications.html

于 2013-10-16T10:24:13.937 回答