随笔分类 - android
摘要:首先需要引入依赖 implementation 'com.squareup.okhttp3:okhttp:4.8.0' implementation 'com.squareup.okio:okio:2.7.0' implementation 'com.squareup.retrofit2:retro
阅读全文
摘要:引入依赖 def room_version = "2.2.5"implementation "androidx.room:room-runtime:$room_version"implementation "androidx.room:room-ktx:$room_version"kapt "and
阅读全文
摘要:action 界面 ACTION_SETTINGS 系统设置界面 ACTION_APN_SETTINGS APN设置界面 ACTION_LOCATION_SOURCE_SETTINGS 定位设置界面 ACTION_AIRPLANE_MODE_SETTINGS 更多连接方式设置界面 ACTION_DA
阅读全文
摘要:<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 背景颜色 --> <sol
阅读全文
摘要:宽高一定要设置否者设置宽高时,(popupwindow)需要注意高度要减去顶部状态栏的高度 (如果你的activity是全屏模式的话,可以不用处理)当然我们也可以自己设置高度 比如可以设置屏幕高度的一半或者其他 //获取顶部状态栏的高度val resourceId: Int = context.re
阅读全文
摘要:val resourceId: Int = activity.resources.getIdentifier("status_bar_height", "dimen", "android") val statusBarHeight: Int = activity.resources.getDimen
阅读全文
摘要:显示输入法 val manager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? manager?.showSoftInput(v, InputMethodManager.SHOW_I
阅读全文
摘要://添加tab 并设置为已选中 tab_layout.addTab(tab_layout.newTab().setText("请选择"),0,true) //跳转到selectedPos位置,并让其置顶(只要有置顶的条件) (recycle_view.layoutManager as LinearL
阅读全文
摘要:首先要重写 DataSource ItemKeyedDataSource 根据数据的最后一条数据的ID 得到下一页的数据 PageKeyedDataSource 这个是普通的分页(第一页,第二页) PositionalDataSource 按照索引位置加载数据 比如是索引0 一页显示20条数据 对应
阅读全文
摘要:需要在res/value/下常见attrs.xml 文件 <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView"> <attr name="bgColor" format="color"
阅读全文
摘要:一般下载文件之前,想要预先知道文件的大小 根据大小就可以拆分该文件进行多线程下载 最后合并即可 (合并就是把下载好的片段 按照正确的顺序写入到一个文件里即可) val request = Request.Builder().head().url("下载文件的地址").build() val resp
阅读全文
摘要:使用startForegroundService + startForeground 首次启动没有问题 但是第二次启动时出现问题 闪退 错误信息说是 没有调用startForeground 试了很多遍,问题一直出现 暂时解决方案 建立一个单例帮助类 使用全局Context 绑定我们写好的音频服务 我
阅读全文
摘要:android { ...... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } //kotlin 默认使用1.6编译 这里修改为使用
阅读全文
摘要:在从其他页面返回该页面 时 使用 PagedList.size 就可以获取到数据量 (size除了其他页面返回该页面 能获取到数据量,其他情况都返回0) viewModel.pagedList..observe(viewLifecycleOwner, Observer { //removeWeakC
阅读全文
摘要:activity 接收参数时时 重写 onNewIntent 接收参数信息 进行相应操作
阅读全文
摘要:需要调用setHasOptionsMenu(true) 否则的话 onCreateOptionsMenu 方法不会执行
阅读全文
摘要:需要实现 ViewModelProvider.Factory class MyModel(val id: String) : ViewModel() { class ViewModeFactory(private val id: String) : ViewModelProvider.Factory
阅读全文
摘要:需要监控生命周期类需要实现LifecycleObserver 把需要检测的生命周期方法添加相应的注解 方法名随意 注解正确就可以 class MyObserver:LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) fun
阅读全文
摘要:使用 startService启动服务 bindService绑定服务 然后unbindService解绑服务 service执行的任务会继续执行,比如播放音乐的服务 如果不使用startService 直接调用绑定 解绑后音乐就停止了
阅读全文
摘要:、 双击signingReport 就会显示密钥信息
阅读全文