본문 바로가기

Development/Android

[Android] Notification Bar View Custom 하기~!


final NotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);

    final Notification notification = new Notification(android.R.drawable.ic_input_add, message, System.currentTimeMillis());

    final RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.noti_content_view);

    views.setImageViewResource(R.id.noti_image, android.R.drawable.ic_input_add);     // for displaying icon on notification

    views.setTextViewText(R.id.noti_text, "Your text here");   // for displaying text on notification    

    notification.contentView = views;

    notification.flags = Notification.FLAG_AUTO_CANCEL;

        manager.notify(1234, notification);


위에는 소스코드 이고 아래는 예제 Xml


<?xml version="1.0" encoding="utf-8"?>


<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"

              android:background="#00ffff"

              >

    <ImageView android:id="@+id/noti_image"

              android:layout_width="wrap_content"

              android:layout_height="fill_parent"

              android:layout_marginRight="10dp"

              />

    <TextView android:id="@+id/noti_text"

              android:layout_width="wrap_content"

              android:layout_height="fill_parent"

              android:textColor="#000"

              />

</LinearLayout>


위의 코드를 적용하면 아래와 같이 나온다~!