2016-12-25 94 views
0

所以我正在學習在xamarin android中使用BigTextStyle進行通知。由於某種原因,每當我運行我的代碼時,bigText和SetSummaryText都沒有出現在通知中。有人知道爲什麼我的代碼如下:Notification.BigTextStyle沒有出現

 protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView (Resource.Layout.Main); 
     Notification.Builder builder = new Notification.Builder(this) 
      .SetContentTitle("Big Text") 
      .SetSmallIcon(Resource.Drawable.Icon); 


     Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); 

     string longTextMessage = "I went up on one pair of stairs."; 
     longTextMessage += "/Just like me. "; 

     textStyle.BigText(longTextMessage); 
     textStyle.SetSummaryText("The summary text goes here. "); 
     builder.SetStyle(textStyle); 
     Notification notification = builder.Build(); 


     NotificationManager notificationManager = 
      GetSystemService(Context.NotificationService) as NotificationManager; 

     const int notificationId = 0; 
     notificationManager.Notify(notificationId, notification); 
    } 

回答

0

enter image description here

var notification = new Notification.Builder(Application.Context) 
    .SetSmallIcon(Resource.Mipmap.Icon) 
    .SetLargeIcon(BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Mipmap.Icon)) 
    .SetAutoCancel(true) 
    .SetStyle(new Notification 
       .BigTextStyle() 
       .SetSummaryText("Summary Text") 
       .SetBigContentTitle("Content Title") 
       .BigText("Big Text Area") 
      ) 
    .Build(); 
var notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService); 
notificationManager.Notify(1, notification); 
+0

這也不能工作。我在運行android 4.4的Samsung Galaxy 4上調試它。 – user2626734

+0

沒關係,它的工作!謝謝。 – user2626734