2014-04-16 32 views
5

Tôi cần tạo thông báo tùy chỉnh thay vì thông báo mặc định trong Android. thông báo hiện tại có một biểu tượng, tiêu đề và thông báo như bên dưới hình ảnhCách tạo Thông báo tùy chỉnh trong android

enter image description here

Tôi muốn nó tùy chỉnh như thế này

enter image description here

làm thế nào tôi có thể đạt được điều này

+1

Kiểm tra tại đây http://codeversed.com/expandable-notifications-android/ – upenpat

Trả lời

7

Notification xem

Normal View - Một thông báo theo quan điểm bình thường xuất hiện trong một khu vực cao tới 64 dp. Ngay cả khi bạn tạo thông báo có kiểu xem lớn, thông báo sẽ xuất hiện ở chế độ xem bình thường cho đến khi được mở rộng.

Content title 
Large icon 
Content text 
Content info 
Small icon 
Notification time 

Normal View Giống như enter image description here

Big Xem - xem lớn của một thông báo chỉ xuất hiện khi thông báo được mở rộng, trong đó xảy ra khi thông báo là ở phía trên cùng của ngăn kéo thông báo hoặc khi người dùng mở rộng thông báo bằng cử chỉ. Thông báo mở rộng được giới thiệu lần đầu tiên trong Android 4.1 JellyBean [API 16]. Expandable notifications được thiết kế để hỗ trợ các đối tượng kiểu thông báo phong phú được gọi là Notification.Style.

Big Xem Giống như

enter image description here

Tới liên kết này expandable-notifications-android

Thông tin thêm về chính thức docs

+0

Điều gì sẽ xảy ra nếu cần bố cục tùy chỉnh? – IteratioN7T

3

Đó gọi Expanded layouts mà có sẵn ngay từ phiên bản Jelly Bean.

Có 2 quan điểm của Thông báo:

  1. Normal View
  2. Big Xem

xem lớn của một thông báo chỉ xuất hiện khi thông báo được mở rộng, trong đó xảy ra khi thông báo là tại đầu ngăn thông báo hoặc khi người dùng mở rộng thông báo bằng cử chỉ. Thông báo mở rộng được giới thiệu lần đầu tiên trong Android 4.1 JellyBean [API 16].

Trong trường hợp của bạn, bạn chỉ muốn hiển thị hình ảnh lớn trong thông báo, cung cấp cho Notification.BigPictureStyle thử:

Bitmap remote_picture = null; 

// Create the style object with BigPictureStyle subclass. 
NotificationCompat.BigPictureStyle notiStyle = new 
     NotificationCompat.BigPictureStyle(); 
notiStyle.setBigContentTitle("Big Picture Expanded"); 
notiStyle.setSummaryText("Nice big picture."); 

try { 
     remote_picture = BitmapFactory.decodeStream(
       (InputStream) new URL(sample_url).getContent()); 
} catch (IOException e) { 
     e.printStackTrace(); 
} 

// Add the big picture to the style. 
notiStyle.bigPicture(remote_picture); 
0

bạn có thể sử dụng NotificationCompat rằng cần remoteview.dưới đây tôi đặt bố trí tùy chỉnh của tôi tên là
activity_downlaodactivity

NotificationManager manager = (NotificationManager)  getSystemService(Context.NOTIFICATION_SERVICE); 
    RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.activity_downlaodactivity); 


    android.support.v4.app.NotificationCompat.Builder mBuilder = 
      new android.support.v4.app.NotificationCompat.Builder(this) 
      .setContent(contentView) 

    manager.notify(0, mBuilder.build()); 
4

Tôi đã tạo ra thông báo usingby sau http://developer.android.com/wear/notifications/creating.html

Thêm mã cho tạo thông báo.

// Specify the 'big view' content to display the long 
// event description that may not fit the normal content text. 
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); 
bigStyle.bigText(eventDescription); 

NotificationCompat.Builder notificationBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.ic_event) 
     .setLargeIcon(BitmapFractory.decodeResource(
       getResources(), R.drawable.notif_background)) 
     .setContentTitle(eventTitle) 
     .setContentText(eventLocation) 
     .setContentIntent(viewPendingIntent) 
     .addAction(R.drawable.ic_map, 
       getString(R.string.map), mapPendingIntent) 
     .setStyle(bigStyle); 
Các vấn đề liên quan