2017-05-26 69 views
0

我在android自定义通知中工作,为此我设计了自定义布局。但是当我收到通知时,此布局的某些部分未显示。 please check the screen shot of Notification通知未显示完整布局

请有人建议我如何使用自定义布局Notifications.how有史以来我的代码如下所示。

我实际的自定义布局代码是

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:orientation="vertical"> 

    <LinearLayout 

     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="12dp" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/notificationHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="@string/startedVideoStreaming" 
      android:textAppearance="?android:textAppearanceMedium" 
      android:textColor="#000" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="1.5dp" 
     android:background="@color/silvercolor"></LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:orientation="horizontal" 
     android:weightSum="4"> 

     <TextView 
      android:id="@+id/pauseId" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:gravity="center" 
      android:text="pause" 
      android:textAppearance="?android:textAppearanceMedium" 
      android:textColor="#000" /> 

     <TextView 
      android:id="@+id/stopLiveId" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:gravity="center" 
      android:text="StopLive" 
      android:textAppearance="?android:textAppearanceMedium" 
      android:textColor="#000" /> 
    </LinearLayout> 
</LinearLayout> 

和我的Android代码是

private void showForegroundNotification() { 
     RemoteViews contentLayout = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); 
     contentLayout.setTextViewText(R.id.notificationHeader, getString(R.string.startedVideoStreaming)); 
     contentLayout.setTextViewText(R.id.pauseId, "Pause"); 
     contentLayout.setTextViewText(R.id.stopLiveId, "StopLive"); 

     final NotificationManager notifyManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     // Intent to call our activity from background. 
     Intent notificationIntent = new Intent(this, MainActivity.class); 
     notificationIntent.setAction(Intent.ACTION_MAIN); 
     notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

     // The PendingIntent to launch our activity if the user selects this notification. 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

     Notification notification = null; 
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      notification = new Notification.Builder(getApplicationContext()) 
        .setContent(contentLayout) 
        .setContentIntent(contentIntent) 
        .setSmallIcon(R.drawable.ic_launcher) 
        .setWhen(System.currentTimeMillis()) 
        .setOngoing(true) 
        .setDefaults(Notification.DEFAULT_SOUND) 
        .setLights(Color.WHITE, 500, 500) 
        .build(); 
     } 

     notification.flags = Notification.FLAG_NO_CLEAR; 
     notifyManager.notify(STREAMER_NOTIFICATION_ID, notification); 
    } 

请有人帮助才能摆脱这种局面

回答

0

这个当前的代码,删除以下代码行

.setContent(contentLayout) 

添加时,您设置标志

notification.bigContentView = contentLayout; 
notification.flags = Notification.FLAG_NO_CLEAR; 
+0

@ msh.narayan它好工作线之上。谢谢 – basha

+0

@Basha如果这段代码可以帮助你,请接受答案。以后人们会受益。谢谢。 –