Use Notification in Android to implement wide view Notification bar (notification Example 2) and Notification Large View
Notification is a message displayed outside of your application's general interface. When the app asks the system to send a message, the message is first displayed in the notification bar in a chart. To view the details of a message, go to the notification drawer. Notification bar and notification drawer
Icationicationdrawer is controlled at the system level. You can view it at any time, not limited to apps.
NotificationDesign:
As an important part of android UI, notification has its own design guidelines.
The Notification interface element has two display modes in the notification drawer, depending on your android version and the status of notification drawer:
(1) Common View
This style is the standard display mode of notification drawer.
Common View blog link: http://www.cnblogs.com/panhouye/p/6139386.html
(2) wide view
It indicates that a larger view is displayed when your notification is expanded. This style is new only after android4.1.
The following describes the wide view in detail:
Only when the notification is expanded, the notification of the wide view will appear. You can expand a common notification through the gesture operation (some custom systems are not allowed, and the wide view will be displayed directly ). This style of notification is supported only after android4.1. The following shows the inbox notification:
You should have noticed that this notification is actually not much different from ordinary ones,
The only difference is the number 7-Details area.
The display of different wide view notification varies according to the following styles:
Big icon style: The details area shows a bitmap with the highest bits 256dp.
Text style: a text section is displayed in the details area.
Inbox style: displays several lines of text in the details area.
The following is our demonstration:
The code implementation is started below. Here we will not go into details about how to click the button layout. We will go directly to the java notification implementation code:
1 public class MainActivity extends AppCompatActivity {2 private static final int NO_2 = 0x2; 3 @ Override 4 protected void onCreate (Bundle savedInstanceState) {5 super. onCreate (savedInstanceState); 6 setContentView (R. layout. activity_main); 7} 8 // Button clicking Method 9 public void show (View v) {10 icationicationcompat. builder builder = new NotificationCompat. builder (this); 11 builder. setSmallIcon (R. mipmap. guojia); 12 builder. setContentTitle ("guo jia"); // system limit, 13 builder may not be displayed. setContentText ("Let's call yuan shaoba"); // system limit, may not display 14 builder. setDefaults (Notification. DEFAULT_ALL); 15 // Add a wide view 16 icationicationcompat. inboxStyle style = new NotificationCompat. inboxStyle (); 17 style. setBigContentTitle ("Ten wins and ten wins"); 18 // The number of 19 styles displayed is determined by the phone's screen pixels. addLine ("first is daosheng"); 20 style. addLine ("Second, Yisheng"); 21 style. addLine ("the third is Zhisheng"); 22 style. addLine ("the fourth is du Sheng"); 23 style. addLine ("Fifth is winning"); 24 style. addLine ("Sixth is desheng"); 25 style. addLine ("seventh is rensheng"); 26 style. addLine ("Eighth is mingsheng"); 27 style. addLine ("ninth is Wensheng"); 28 style. addLine ("Tenth is wusheng"); 29 style. setSummaryText ("Author: guo jia"); // Add 30 builder. setStyle (style); 31 Notification n = builder. build (); 32 icationicationmanager manager = (icationicationmanager) getSystemService (Context. NOTIFICATION_SERVICE); 33 manager. Y (NO_2, n); 34} 35}
Today, we briefly demonstrated the implementation of the notification wide view. Let's take a look at it before going to bed. Good night.