我在Android自定义通知中工作,因为我设计了自定义布局。但是当我收到通知时这个布局的某些部分没有显示出来。 please check the screen shot of Notification
请有人建议我如何使用Notifications的自定义布局。我的代码如下所示。
我的实际自定义布局代码是
<?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>
我的安卓代码是
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 :(得分:0)
使用此当前代码,从代码中删除以下行
.setContent(contentLayout)
在设置标志
时添加上面的行notification.bigContentView = contentLayout;
notification.flags = Notification.FLAG_NO_CLEAR;