- 如果通知的text很长的话,可以如下设置
NotificationCompat.Builder(getApplicationContext(), PRIMARY_CHANNEL)
.setContentTitle(title)
//不需要设置text
//.setContentText(text)
//设置BigTextStyle
setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.long_notification_text)));
.setWhen(System.currentTimeMillis())
.setSmallIcon(getSmallIcon())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round))
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(true);
- 如果想在通知下面显示一张图片,可如下设置
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),
R.drawable.ic_notification_big)));
使用约束布局通知显示不出来。
调用NotificationCompat.Builder的setOngoing方法,传入参数为true即可。
public Builder setOngoing(boolean ongoing) {
setFlag(Notification.FLAG_ONGOING_EVENT, ongoing);
return this;
}
android.widget.AdapterViewFlipper
android.widget.FrameLayout
android.widget.GridLayout
android.widget.GridView
android.widget.LinearLayout
android.widget.ListView
android.widget.RelativeLayout
android.widget.StackView
android.widget.ViewFlipper
android.widget.AnalogClock
android.widget.Button
android.widget.Chronometer
android.widget.ImageButton
android.widget.ImageView
android.widget.ProgressBar
android.widget.TextClock
android.widget.TextView