复习内容
通知 Notification
Notification
说一下今天付下了一下Notification 的内容 和使用
1.首先要一个NotificationManager来进行管理,用getSystemService方,这里传入一个Context。NOTIFICAATION_SERVICE就可以了。
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2.创建 NotificationCompat.Builder 来进行 Notification 的初始化
Notification notification = new NotificationCompat.Builder(MainActivity.this).build();\
4.之后我们就可以去使用Notification了
notification.setContentTitle("这是测试通知标题") //设置标题
notification .setContentText("这是测试通知内容") //设置内容
notification .setWhen(System.currentTimeMillis()) //设置时间
notification .setSmallIcon(R.mipmap.ic_launcher) //设置小图标
5.最后我们要进行显示设置 也就是让NotificationManager 来进行显示设置
manager.notify(1,notification);
自定义View的复习
1.绘制扇形
paint.setColor(Color.BLACK);
paint.setStrokeWidth(13);
RectF rectF = new RectF(200,200,700,700); //初始化位置
paint.setColor(Color.RED);
canvas.drawArc(rectF,225,45,true,paint);//参数一:初始化的位置,参数二:开始绘制的起始角度 参数三:绘制度数 参数四:是否连接 参数五 :画笔
paint.setColor(Color.GREEN);
canvas.drawArc(rectF,-90,90,true,paint);
paint.setColor(Color.BLUE);
canvas.drawArc(rectF,0,90,true,paint);
paint.setColor(Color.YELLOW);
canvas.drawArc(rectF,90,135,true,paint);
paint.setColor(Color.RED);
今日份的Kotlin
高阶函数 与 lambda表达式
先说一下什么Lambda
Lambda是一种函数的表示方式(言外之意也就是说一个Lambda表达式等于一个函数),更确切的说:Lambda是一个未声明的函数,会以表达式的形式传递
Lambda表达式语法:
1. lambda 表达式总是被大括号括着;
2. 其参数(如果有的话)在 -> 之前声明(参数类型可以省略);
3. 函数体(如果存在的话)在 -> 后面
例:
// 第一种
val sum1 = {x: Int, j: Int -> x + j}
// 第二种
val sum2: (x: Int, j: Int) -> Int = {a, b -> a + b }
什么叫做高阶函数:
以函数作为参数或返回函数的函数被称为高阶函数
首先我们先定义一个高阶函数:
fun 高阶函数名(参数函数名:参数函数类型):高阶函数返回类型{
高阶函数体
}
写一个例子:
fun highOrderFunc(arg1: Int, arg2: Int, paramFunc: (a: Int, b: Int) -> Boolean): Int {
return if (paramFunc(arg1, arg2)) {
arg1
} else {
arg2
}