2012-08-13 28 views
1

我有一個通知,其中包含少量文本,但它仍然很大,因此它會顯示在通知欄中,因此它被縮寫。唯一的解決方案,我發現它做出了自定義通知,但它似乎有點矯枉過正,我想要做的。在通知中滾動文本

我可以使通知滾動文本或擴大通知文本區域,因此它將顯示全文而不僅僅是它的前幾個單詞嗎?

我目前調用與通知:

private void triggerNotification() { 
     Notification notification = new Notification(R.drawable.ic_launcher, 
       "Title", System.currentTimeMillis()); 
     notification.setLatestEventInfo(this, "First text", 
       "This is the text that gets abberviated with .. when it is too long", 
       PendingIntent.getActivity(this, 0, new Intent(this,MainActivity.class) 
         .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 
         PendingIntent.FLAG_CANCEL_CURRENT)); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     nm.notify(0, notification); 


} 
+0

你的min-sdk支持什麼? – iTurki 2012-08-13 17:36:14

+0

android:minSdkVersion =「8」 – Nick 2012-08-13 17:38:44

回答

2

在API 16+,有一個Notification.Builder類,允許你添加一個subtext可以是多線(象Gmail notifications)。我不知道Notification.Builder是否包含在the support library中,但我想它可能是。你可以檢查它。

但是,如果它不在支持庫中,並且必須堅持使用minSdkVersion,恐怕除了實現自己的通知版本之外,沒有辦法做到您想要的功能。


UPDATE:

(被髮佈於2012年8月修訂版10)支持庫的最後修訂介紹了Android 4.1的通知樣式:BigTextStyle。有一個如何使用它的好例子。檢查它here