Android uses notification to implement wide view notification bar (ii) _android

Source: Internet
Author: User

Notification is a message that is displayed outside of your application's regular interface. When the app lets the system send a message, the message is first displayed as a chart in the notification bar. To see the details of the message you need to go to the notification drawer (notificationdrawer) to view it. The notification and notification drawers (Notificationdrawer) are system-level controlled and you can view them at any time, not limited to the app.

The design of Notification:

As an important part of the Android UI, notification has proprietary design guidelines.

Notification interface elements in the notification drawer notification there are two ways to display, depending on your Android version and notification drawer status:

(1) Normal view

This style is the standard display method of notification drawer.

Normal View Blog Link: http://www.jb51.net/article/99307.htm

(2) Wide view

When your notification is expanded it will show a larger view, which is a new feature after android4.1.

The broad view is described in detail below:

This wide view of the notification will only appear when the notification is expanded, and gestures can be used to expand a common notification (part of the custom system is not able to display a wide view directly). This style of notification from the android4.1 later began to support. The screenshot below shows the inbox style of notification:

You should have noticed that this kind of notification is actually not much different from normal,

The only difference is the number 7-detail area.

The different wide view notification the display here is different, has the following several styles:

Large icon Style: The detail area displays a top-bit 256DP bitmap.

Text Style: Detail area displays a paragraph of text

message box style (Inbox style): The details area displays a few lines of text.

Here are the results of our demo:

The following start code implementation, here is not to repeat the Click button layout, directly on the Java Notification Implementation code:

public class Mainactivity extends Appcompatactivity {private static final int no_2 =0x2;
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.layout.activity_main);
    //button click Method public void Show (View v) {notificationcompat.builder Builder = new Notificationcompat.builder (this);
    Builder.setsmallicon (R.mipmap.guojia); Builder.setcontenttitle ("Guo Jia");//system limitations, may not show builder.setcontenttext ("Let's play Yuan Shao");/system limitations, may not show builder.setdefaults (
    Notification.default_all);
    Add wide view Notificationcompat.inboxstyle style = new Notificationcompat.inboxstyle ();
    Style.setbigcontenttitle ("10 wins ten defeats");
    The cell phone screen pixel determines how many style.addline ("First is the road wins");
    Style.addline ("Second is righteousness wins");
    Style.addline ("Third is Victory");
    Style.addline ("Four is the degree of victory");
    Style.addline ("The five is seeking to win");
    Style.addline ("Sixth is Tak Sheng");
    Style.addline ("Seventh is Ren Sheng");
    Style.addline ("Eighth is Meanwin");
    Style.addline ("Nineth is Wen Sheng");
    Style.addline ("Tenth is Wusheng"); Style.setSummarytext ("Author: Guo Jia");//Add Summary builder.setstyle (style);
    Notification n = builder.build ();
    Notificationmanager manager = (Notificationmanager) getsystemservice (Context.notification_service);
  Manager.notify (no_2, N); }
}

Today, this is a simple demonstration of notification's wide view implementation.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.