如何在状态栏中的通知顶部添加我的自定义布局?

时间:2013-10-16 10:19:03

标签: android android-layout notifications

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

有没有办法做到这一点?

1 个答案:

答案 0 :(得分: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

相关问题