NetBlog主题

android Kotlin实现绘制交流电压波形图
Android基础

android Kotlin实现绘制交流电压波形图

78

1.创建自定义 View,创建一个继承自View的自定义类,在这个类中实现波形图的绘制逻辑。package com.zhkh.khpec.utilityimport android.content.Contextimport android.graphics.Canvasimport android.graphics.Colorimport android.graphics.Paintimport android.util.Att…

Android Kotlin 计算耗时,显示时分秒
Android基础

Android Kotlin 计算耗时,显示时分秒

129

@SuppressLint("DefaultLocale")@RequiresApi(Build.VERSION_CODES.O)private fun CalculationTime(){ val dt11 = System.currentTimeMillis() // 获取当前时间(毫秒) while (true){ val dt21 = System.currentTimeMillis() // 再次获取当前时间(毫秒)…

Android Kotlin 自定义弹出对话框
Android基础

Android Kotlin 自定义弹出对话框

161

效果图自定义activity_userinfo.xml文件代码?xml version="1.0" encoding="utf-8"?LinearLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" androi…

Kotlin 获取当前代码位于文件位置信息
Android基础

Kotlin 获取当前代码位于文件位置信息

135

fun getCodeInfo(element: ArrayStackTraceElement):String { val fileName = element[2].fileName val lineNumber = element[2].lineNumber return "lqwvje,当前代码位于文件:$fileName ,行号:$lineNumber"}方法调用val msg=getCodeInfo(Thread.currentThr…

Android Kotlin 实现弹出确认提示框
Android基础

Android Kotlin 实现弹出确认提示框

248

效果如下核心代码private fun showConfirmationDialog(context:Context) val builder = AlertDialog.Builder(context) builder.setTitle("确认操作") .setMessage("你确定要删除吗?") .setPositiveButton("确定") { dialog, which - //…

Android Kotlin SQLite读写操作源码实例
Android基础

Android Kotlin SQLite读写操作源码实例

267

package com.zhkh.khpec.utilityimport android.annotation.SuppressLintimport android.content.Contextimport android.database.sqlite.SQLiteDatabaseimport android.database.sqlite.SQLiteOpenHelperclass DatabaseHelper(context: Context?) : SQLiteOpenHelper(con…

Android Kotlin 字符串与字节数组(byte[])互转
Android基础

Android Kotlin 字符串与字节数组(byte[])互转

461

val s = "罗分明"val byteArray = s.toByteArray(Charsets.UTF_8)//打印输出 e7 bd 97 e5 88 86 e6 98 8eprintln(byteArray.toHexString().chunked(2).joinToString(" "))val s2 = String(byteArray, Charsets.UTF_8)//打印输出 罗分明println(s2)本文来自www.luofenmin…