05 2025 档案
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_
阅读全文
摘要:一,代码: adapter public class MyRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private Context context; private static final int
阅读全文
摘要:一,代码: adapter: package com.example.okdemo1.adapter; import androidx.recyclerview.widget.RecyclerView; import android.content.Context; import android.v
阅读全文
摘要:一,代码: xml: activity <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.co
阅读全文
摘要:一,代码: 1,xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/re
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res
阅读全文
摘要:一,官方文档: https://developer.android.google.cn/training/data-storage/shared/photopicker?authuser=5&hl=zh-cn#java 二,代码: package com.example.okdemo1.activi
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,不要再使用onBackPressed onBackPressed() 在Android 13中被弃用,即当build中compileSdkVersion和targetSdkVersion为33及以上,onBackPressed()被弃用 二,代码: public class MainActivi
阅读全文
摘要:一,添加字体文件 在res目录下创建font目录,然后把字体文件复制到此目录下,注意:字体文件的文件名请使用英文小写字符 二,代码: xml: <TextView android:id="@+id/textView" android:layout_width="wrap_content" andro
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,代码: public class AnimActivity extends AppCompatActivity { private Handler handler = new Handler(); private static final long DELAY_TIME = 3000; // 3
阅读全文
摘要:一,代码: 在oncreate生命周期中添加代码: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 如下: protected void onCreate(Bundle savedInstanceState) {
阅读全文
摘要:一,代码: 原activity //得到launcher ActivityResultLauncher launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new Act
阅读全文
摘要:一,代码: //给按钮增加点击事件:旋转 Button rotateButton = findViewById(R.id.rotateButton); rotateButton.setOnClickListener(new View.OnClickListener() { @Override pub
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,代码 线上的数据: activity package com.example.okdemo1.activity; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import an
阅读全文
摘要:一,代码: 线上的数据: activity package com.example.okdemo1.activity; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import a
阅读全文
摘要:一,代码: 线上的数据: activity package com.example.okdemo1.activity; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import a
阅读全文
摘要:一,报错信息 Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not foun
阅读全文
摘要:一,创建application 代码: package com.example.okdemo1; import android.app.Application; import android.content.res.Configuration; import androidx.annotation.
阅读全文
摘要:一,代码: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/an
阅读全文
摘要:一,代码: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/an
阅读全文
摘要:一,代码: <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res
阅读全文
摘要:一,安装第三方库: 地址: https://mvnrepository.com/artifact/com.google.code.gson/gson build.gradle中dependencies添加: implementation 'com.google.code.gson:gson:2.13
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res
阅读全文
摘要:一,代码: gson库安装方式见我其他博文 传递对象的类: package com.example.okdemo1.model; public class Goods1 { //商品id private int id; //商品名称 private String name; public Goods
阅读全文
摘要:一,代码: 1,用来传递对象的类 package com.example.okdemo1.model; import java.io.Serializable; public class Goods2 implements Serializable { //商品id private int id;
阅读全文
摘要:一,代码: 1,所传递对象的类 package com.example.okdemo1.model; import android.os.Parcel; import android.os.Parcelable; public class Goods3 implements Parcelable {
阅读全文
摘要:一,官方文档 https://developer.android.google.cn/studio/debug?authuser=1&hl=zh-cn 二,启动调试 1,点击工具栏上按钮,启动调试 2,对运行的进程进行调试: 点击工具栏上的Attach debugger to Android pro
阅读全文
摘要:一,官方文档: https://developer.android.google.cn/guide/components/activities/activity-lifecycle?hl=zh-cn 官方对生命周期的说明图 二,代码: package com.example.okdemo1; imp
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res
阅读全文
摘要:一,两种方式: ViewTreeObserver.OnGlobalLayoutListener 可以监听视图树的全局布局事件,当视图树的布局发生变化时会触发回调。通过这种方式可以在视图布局完成后获取其宽高。 View.post 方法可以将一个 Runnable 放入视图的消息队列中,当视图布局完成后
阅读全文
摘要:一,只隐藏状态栏 在onCreate事件中,setContentView前添加 //只隐藏状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 效果: 二,同时隐藏状态栏和导航栏 在onCreate事件中,setC
阅读全文
摘要:一,代码: public class FrameActivity extends AppCompatActivity { private View pushView; private int deOptions; //系统可见性的选项 private View decorView; @Overrid
阅读全文
摘要:一,代码: package com.example.okdemo1.activity; import static android.app.PendingIntent.getActivity; import android.animation.Animator; import android.ani
阅读全文
摘要:一,类代码: package com.example.okdemo1.lib; import android.util.Log; public class Logger { /* public static final int VERBOSE = 2; public static final int
阅读全文
摘要:一,代码: 说明:要使用layui的lay-filter html: <div class="layui-form layui-col-md6" style="margin-left: 6px;width:130px;margin-top:16px;"> <select name="type" id
阅读全文
摘要:一,代码: //给按钮增加点击事件 Button button2 = findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(V
阅读全文
摘要:一,代码: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match
阅读全文
摘要:一,报错信息: Caused by: android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f050224 Caused by: android.content.re
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp"
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,常用属性: 常用属性: layout_constraintLeft_toLeftOf:左边和目标组件的左边对齐layout_constraintLeft_toRightOf:左边和目标组件的右边对齐layout_constraintRight_toLeftOf:右边和目标组件的左边对齐layou
阅读全文
摘要:一,代码: rouned_corner.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectan
阅读全文
摘要:一,代码: press_rounded_corner.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item andr
阅读全文
摘要:一,安装第三方库: 库地址: https://mvnrepository.com/artifact/org.greenrobot/eventbus 编辑build.gradle, 添加以下内容: // https://mvnrepository.com/artifact/org.greenrobot
阅读全文
摘要:一,权限 <uses-permission android:name="android.permission.INTERNET"/> 二,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.
阅读全文
摘要:一,在已有项目中创建模块: 项目上右键->New->Module 类型选择Android Library,并为模块命名 创建完成后,新模块的目录和app是平级的 可以看到项目的settings.gradle已经包含了新建的模块 二,配置依赖 1,主模块app的build.gradle的depende
阅读全文
摘要:一,配置build.gradle 1,增加以下三行: 如下 2,在buildTypes中增加debug buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-
阅读全文
摘要:一,报错信息: 给buildTypes增加了debug段后, buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'prog
阅读全文
摘要:一,要替换的图标: 二,图标文件的大小 替换上图中的五个不同size的:ic_launcher.webpic_launcher_round.webp 分别是: mdpi: 48x48 pxhdpi: 72x72 pxxhdpi: 96x96 pxxxhdpi: 144x144 pxxxxhdpi:
阅读全文
摘要:一,报错信息: /Users/liuhongdi/StudioProjects/okdemo1/app/src/main/java/com/example/okdemo1/activity/FreshActivity.java:28: 错误: 无法访问NestedScrollingParent re
阅读全文
摘要:一,安装第三方库 官网: https://gitee.com/scwang90/SmartRefreshLayout#english--%E4%B8%AD%E6%96%87 库地址: https://mvnrepository.com/artifact/io.github.scwang90/refr
阅读全文
摘要:一,代码: package com.example.okdemo1.activity; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import
阅读全文
摘要:一,设置app名字 编辑AndroidManifest.xml中的android:label一项即可 修改相应的值即可 设置后在手机中的显示: 二,代码中获取app名字 //给按钮增加点击事件 Button myButton = findViewById(R.id.button); myButton
阅读全文
摘要:一,设置版本: 1,versionCode和 versionName的区别 1. 版本名称(Version Name) 版本名称是一个字符串,用于向用户展示当前应用的版本。例如,“1.0.0”、“2.5.1”等。这个名称通常由开发者定义,用于标识应用的版本,便于用户理解。 2. 版本代码(Versi
阅读全文
摘要:一,配置权限 在AndroidManifest.xml中添加权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 说明: 当目标系统在Android 13及以上, WRITE_EXTERNAL_
阅读全文
摘要:一,代码: xml: activity_frag_page.xml(外层viewpager2) <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:androi
阅读全文
摘要:一,代码: 给内部的viewpager2外面包上一层NestedScrollableHost java代码: package com.example.okdemo1.lib; import android.content.Context; import android.util.AttributeS
阅读全文
摘要:一,代码: 1,xml: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/r
阅读全文
摘要:一,代码: 功能:点击按钮后滑动到相应页面, 手动滑动页面时,下面的按钮能指示当前滑动到的页面 页面最下方的三个按钮,相当于我们自定义的tabbar 1,xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.wid
阅读全文
摘要:一,问题: xml: <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="200px"> <Button android:id="@+id/
阅读全文
摘要:一,代码: 1,xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/re
阅读全文
摘要:一,代码: xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
阅读全文
摘要:一,代码: 说明: View.VISIBLE:表示View是可见的,即显示在屏幕上。 View.INVISIBLE:表示View是不可见的,但仍然占据空间。 View.GONE:表示View是不可见的,并且不占据空间1。 xml <?xml version="1.0" encoding
阅读全文
摘要:一,代码 //给按钮增加点击事件 Button webButton = findViewById(R.id.webbutton); webButton.setOnClickListener(new View.OnClickListener() { @Override public void onCl
阅读全文
摘要:一,配置权限: <uses-feature android:name="android.hardware.telephony" android:required="false" /> <uses-permission android:name="android.permission.CALL_PHO
阅读全文
摘要:一,安装第三方库glide 1,库地址: https://mvnrepository.com/artifact/com.github.bumptech.glide/glide 2,安装:编辑build.gradle,在dependencies段增加如下一行 // https://mvnreposit
阅读全文
摘要:一,代码: 在activity的oncreate方法中添加如下代码: //设置状态栏透明 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { getWindow().getDecorView().setSystemUiVisibility(Vi
阅读全文
摘要:一,问题的现象 代码: //给按钮增加点击事件 Button myButton = findViewById(R.id.apibutton); myButton.setOnClickListener(new View.OnClickListener() { @Override public void
阅读全文
浙公网安备 33010602011771号