总结
最后为了帮助大家深刻理解Android相关知识点的原理以及面试相关知识,这里放上相关的我搜集整理的14套腾讯、字节跳动、阿里、百度等2021最新面试真题解析,我把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包知识脉络 + 诸多细节。
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
notificationAPI_11p.flags |= Notification.FLAG_AUTO_CANCEL;
// 通过通知管理器来发起通知。
manager.notify(NOTIFICATION_FLAG, notificationAPI_11p);
}
### 默认通知(API 16+)
#### 效果图
![P3](https://img-blog.csdn.net/20150917142115532)
#### 按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="notificationAPI_16p"
android:text="默认通知(API 16+)" />
#### 实现
/**
- 系统下拉栏默认的通知(API 16+)
*/
public void notificationAPI_16p(View view) {
// 获取NotificationManager管理者对象
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 创建一个PendingIntent,和Intent类似,不同的是由于不是马上调用,需要在下拉状态条出发的Activity,所以采用的是PendingIntent,即点击Notification跳转启动到哪个Activity
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
// 通过Notification.Builder来创建通知,注意API Level 16之后才支持
Notification notificationAPI_16p = new Notification.Builder(this)
// 设置状态栏中的小图片,尺寸一般建议在24×24,这个图片同样也是在下拉状态栏中所显示,如果在那里需要更换更大的图片,可以使用setLargeIcon(Bitmap icon)
.setSmallIcon(R.mipmap.ic_launcher)
// 设置在status bar上显示的提示文字
.setTicker("TickerText:" + "您有新短消息,请注意查收!")
// 设置在下拉status bar后显示的标题
.setContentTitle("这里是标题(API 16+)")
// 设置在下拉status bar后显示的内容
.setContentText("这里是显示的内容")
// 关联PendingIntent
.setContentIntent(pendingIntent)
// 设置在下拉status bar后显示的数字
.setNumber(1)
// 需要注意build()是在API level 16及之后增加的,API11可以使用getNotificatin()来替代
.build();
// FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
notificationAPI_16p.flags |= Notification.FLAG_AUTO_CANCEL;
// 通过通知管理器来发起通知
manager.notify(NOTIFICATION_FLAG, notificationAPI_16p);
}
自定义样式
-----
### 效果图
![P4](https://img-blog.csdn.net/20150917142159065)
### 自定义提示框布局
> 在**layout**目录下添加**my\_notification.xml**文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF000000"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="@+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:gravity="center"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
<ProgressBar
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text_content"
android:layout_gravity="center_vertical"
android:layout_toRightOf="@+id/icon" />
### 按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="myselfNotification"
android:text="自定义通知" />
### 实现
/**
- 系统下拉栏自定义的通知
*/
public void myselfNotification(View view) {
// 获取NotificationManager管理者对象
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Notification myNotify = new Notification(R.drawable.message,
// "自定义通知:您有新短信息了,请注意查收!", System.currentTimeMillis());
mNotification = new Notification();
// 显示的图片
mNotification.icon = R.mipmap.ic_launcher;
// 设置在status bar上显示的提示文字
mNotification.tickerText = "TickerText:您有新短消息,请注意查收!";
// 获取当前系统时间
mNotification.when = System.currentTimeMillis();
// 表明当通知被用户点击时,通知不自动清除。
mNotification.flags = Notification.FLAG_NO_CLEAR;
// 加载自定义的布局
mRemoteViews = new RemoteViews(getPackageName(), R.layout.my_notification);
// 设置图片
mRemoteViews.setImageViewResource(R.id.icon, R.mipmap.ic_launcher);
// 设置文字
mRemoteViews.setTextViewText(R.id.text_content, "下载进度");
// 设置进度
mRemoteViews.setProgressBar(R.id.pb, 100, 10, false);
// 设置显示的自定义布局
mNotification.contentView = mRemoteViews;
// 设置点击通知栏的响应动作
Intent intent = new Intent(Intent.ACTION_MAIN);
// 设置通知的点击响应
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 1);
mNotification.contentIntent = contentIntent;
// 通过通知管理器来发起通知
mNotificationManager.notify(NOTIFICATION_FLAG, mNotification);
}
清除指定ID的通知
---------
### 按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cleanNotificationById"
android:text="清除指定ID的通知" />
### 实现
/**
-
清除指定ID的提示
-
@param view
*/
public void cleanNotificationById(View view){
// 获取NotificationManager管理者对象
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 清除id为NOTIFICATION_FLAG的通知
mNotificationManager.cancel(NOTIFICATION_FLAG);
}
清除所有通知
------
### 按钮
尾声
最后,我再重复一次,如果你想成为一个优秀的 Android 开发人员,请集中精力,对基础和重要的事情做深度研究。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。
这里,笔者分享一份从架构哲学的层面来剖析的视频及资料分享给大家梳理了多年的架构经验,筹备近6个月最新录制的,相信这份视频能给你带来不一样的启发、收获。
Android进阶学习资料库
一共十个专题,包括了Android进阶所有学习资料,Android进阶视频,Flutter,java基础,kotlin,NDK模块,计算机网络,数据结构与算法,微信小程序,面试题解析,framework源码!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
roid进阶学习资料库
一共十个专题,包括了Android进阶所有学习资料,Android进阶视频,Flutter,java基础,kotlin,NDK模块,计算机网络,数据结构与算法,微信小程序,面试题解析,framework源码!
[外链图片转存中…(img-V4mo7EUK-1715138813229)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!