2012-05-09 19 views
5

On HTC điện thoại của tôi RemoteView cho các thông báo trông giống như hình dưới đây ...Đây có phải là bố cục Thông báo Android (RemoteView) không?

enter image description here

Tôi muốn sử dụng cách bố trí tương tự (hình ảnh, chữ in đậm và văn bản nhỏ) cho một thông báo trong tôi ứng dụng nhưng tôi không thể làm việc ra nếu đó là một cổ phiếu Android bố trí hay không. Tôi đã tạo bố cục của riêng mình nhưng nó không hoàn toàn giống nhau và tôi muốn dính vào 'tiêu chuẩn' nếu có thể.

Sử dụng nhật thực Tôi đã thử nhập android.R.layout. để xem gợi ý là gì nhưng tôi không thể thấy bất kỳ tên nào có thể đề xuất bố cục thông báo.

Đây có phải là bố cục của Android không? Nếu có, làm cách nào để truy cập?

Trả lời

5

Đây là bố cục thông báo chuẩn của Android và bạn không cần phải tạo bố cục tùy chỉnh của riêng mình. Chỉ cần sử dụng API thông báo hiện tại để đặt drawable, title và text. Dưới đây là một ví dụ, sử dụng NotificationCompat.Builder từ khả năng tương thích thư viện:

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setContentIntent(pendingIntent) 
     .setWhen(System.currentTimeMillis()) 
     .setTicker(getText(R.string.notification_ticker)) 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentTitle(getText(R.string.notification_title)) 
     .setContentText(getText(R.string.notification_text)); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 

Và tương tự sử dụng Notification lớp:

Notification notification = new Notification(R.drawable.notification_icon, getText(R.string.notification_ticker), System.currentTimeMillis()); 

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

notification.setLatestEventInfo(this, getString(R.string.notification_title), getText(R.string.notification_text), pendingIntent); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 
Các vấn đề liên quan