随笔分类 -  android基础

android的基础知识
摘要:一,引入lifecycle相关库 1,在项目根目录下的build.gradle中配置脚本,增加: buildscript{ ext { lifecycle = "2.5.1" } } 编辑app下的build.gradle,增加: // lifecycle相关 api "androidx.lifec 阅读全文
posted @ 2025-06-22 12:50 刘宏缔的架构森林 阅读(76) 评论(0) 推荐(0)
摘要:一,代码 1,application public class MainApplication extends Application { private static MainApplication mApp; private static Context context; public Hash 阅读全文
posted @ 2025-06-14 15:23 刘宏缔的架构森林 阅读(72) 评论(0) 推荐(0)
摘要:一,报错信息 Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag 原因: activity继承了context重载了startActivity方法,如 阅读全文
posted @ 2025-06-14 15:22 刘宏缔的架构森林 阅读(277) 评论(0) 推荐(0)
摘要:一,报错信息: java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare() 原因: 原因是Android中不允许在子线程中处理UI。如果要在子线程中处理UI那就要动态转到主线程中执行 阅读全文
posted @ 2025-06-14 15:22 刘宏缔的架构森林 阅读(359) 评论(0) 推荐(0)
摘要:一,代码: 如果同时在属性中同时设置了: android:layout_margin="10dp" android:layout_marginTop="30dp" 则只有layout_margin生效,layout_marginTop无效,并不会覆盖layout_margin的值.如果layout_ 阅读全文
posted @ 2025-06-07 11:18 刘宏缔的架构森林 阅读(68) 评论(0) 推荐(0)
摘要:一,代码: 样式文件位置: 内容:注意:name用来供调用 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style nam 阅读全文
posted @ 2025-06-07 11:18 刘宏缔的架构森林 阅读(27) 评论(0) 推荐(0)
摘要:一,安装第三方库 库地址: https://mvnrepository.com/artifact/com.github.barteksc/android-pdf-viewer 编辑build.gradle,添加: // https://mvnrepository.com/artifact/com.g 阅读全文
posted @ 2025-06-07 11:18 刘宏缔的架构森林 阅读(433) 评论(0) 推荐(0)
摘要:一,打开device explorer 二,找到文件后保存 阅读全文
posted @ 2025-06-07 11:18 刘宏缔的架构森林 阅读(27) 评论(0) 推荐(0)
摘要:一,代码: xml上只有一个按钮 java代码: package com.example.okdemo1.activity; import android.Manifest; import android.content.Context; import android.content.Intent; 阅读全文
posted @ 2025-06-07 10:50 刘宏缔的架构森林 阅读(54) 评论(0) 推荐(0)
摘要:一,代码: 添加在AndroidManifest.xml中的FileProvider <provider android:name="androidx.core.content.FileProvider" android:authorities="com.example.okdemo1.filepr 阅读全文
posted @ 2025-06-07 10:50 刘宏缔的架构森林 阅读(108) 评论(0) 推荐(0)
摘要:一,代码 xml只有一个按钮 java: package com.example.okdemo1.activity; import android.Manifest; import android.content.Intent; import android.content.pm.PackageMa 阅读全文
posted @ 2025-06-07 10:50 刘宏缔的架构森林 阅读(80) 评论(0) 推荐(0)
摘要:一,java转kotlin code->Convert Java File to Kotlin File 如图: 弹出提示,需要在项目中配置kotlin 确认 提示一些需要修正 二,一个例子: package com.example.okdemo1.activity import android.o 阅读全文
posted @ 2025-06-02 12:27 刘宏缔的架构森林 阅读(277) 评论(0) 推荐(0)
摘要:一,代码 activity xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/ 阅读全文
posted @ 2025-06-02 12:27 刘宏缔的架构森林 阅读(26) 评论(0) 推荐(0)
摘要:一,代码: activity xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com 阅读全文
posted @ 2025-06-02 12:27 刘宏缔的架构森林 阅读(50) 评论(0) 推荐(0)
摘要:一,报错信息: 错误: 对于add(int,MsgFragment), 找不到合适的方法 fragmentTransaction.add(R.id.fragment_container, fragment); ^ 方法 FragmentTransaction.add(Fragment,String) 阅读全文
posted @ 2025-06-02 12:27 刘宏缔的架构森林 阅读(52) 评论(0) 推荐(0)
摘要:一,创建common目录 然后在common目录下创建layout目录 二,原来在layout目录下的xml需要另放一个目录 我们创建一个main目录,main目录下创建layout,移动到这里 三,在build.gradle中添加已创建目录: //在layout文件夹下建立子文件夹 sourceS 阅读全文
posted @ 2025-06-02 12:27 刘宏缔的架构森林 阅读(128) 评论(0) 推荐(0)
摘要:一,代码: 公用部分 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertic 阅读全文
posted @ 2025-06-02 12:23 刘宏缔的架构森林 阅读(22) 评论(0) 推荐(0)
摘要:一,代码: activity xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com 阅读全文
posted @ 2025-06-02 12:23 刘宏缔的架构森林 阅读(63) 评论(0) 推荐(0)
摘要:一,代码: activity的xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com 阅读全文
posted @ 2025-06-02 12:22 刘宏缔的架构森林 阅读(294) 评论(0) 推荐(0)
摘要:一,代码: activity xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com 阅读全文
posted @ 2025-06-02 12:22 刘宏缔的架构森林 阅读(91) 评论(0) 推荐(0)