Android Normal Style通知详解

1.示例:

此篇文章主要分析红框内的内容。

2.View层级:

View属性:

type(id)WidthHeightMargin(dp)Padding(dp)GravityLayout_gravityVisibilityothers
topbottomstartendtopbottomstartend
FrameLayout(status_bar_latest_event_content)match_parentwrap_content            
LinearLayout(notification_main_column)match_parentwrap_content37.5dp16dp16dp16dp     top vertical
LinearLayout(line1)match_parentwrap_content           horizontal
TextView(title)wrap_contentwrap_content           singleLine
TextView(text_line_1)match_parentwrap_content      16dp end|bottom  singleLine
ImageFloatingTextView(text)match_parentwrap_content0.5dp       toptop singleLine
ProgressBar(progress)match_parent15dp 15dp16dp16dp     bottomgone 
ImageView(right_icon)40dp40dp36dp  16dp     top|end top|end

NotificationHeaderView(notification_header) 参考:https://blog.csdn.net/zhao5214319/article/details/98038482

3.View详解:

  • LinearLayout(notification_main_column):

功能:布局文件,规定标题和内容的位置的,应用中无法修改

  • LinearLayout(line1):

功能:布局文件,规定标题位置,应用中无法修改

  • TextView(title):

功能:通知的Title显示

方法:setContentTitle

  • TextView(text_line_1):

功能:一般用户显示进度条的最大进度值,Title此时显示为当期进度

          也可显示进度条当前进度

方法:同时调用setProgress和setContentText

  • ImageFloatingTextView(text):

功能:显示通知内容

方法:setContentText

  • ProgressBar(progress):

功能:显示进度;一般用来显示下载进度

方法:setProgress

  • ImageView(right_icon):

功能:大图标提示

方法:setLargeIcon

4.示例代码:

@TargetApi(26)
private void createNotificationChannel() {
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID ,CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
    mNotificationManager.createNotificationChannel(channel);
}

@TargetApi(26)
private Notification buildNotification() {
    Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_small));
    builder.setContentTitle("Notification");
    builder.setContentText("I'm is Text");
    builder.setSubText("SubText");
    builder.setProgress(100, 50, false);
    builder.setShowWhen(true);
    builder.setUsesChronometer(true);
    return builder.build();
}

mNotificationManager.notify(NOTIFICATION_ID, buildNotification());

5.总结:

  1. Normal Style通知是使用最多的通知,了解其View的层级以及设置方法可以帮助研发更快的设计需要的通知。
  2. 不调用setStyle方法时,通知默认使用的Style是Noraml。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值