android常用

1.Bean

implementation ‘com.google.code.gson:gson:2.8.4’

1.Gson

"prizeList": [
            {
                "prizeName": "吹风机",
                "prizeImage": "https://stg1-eco.cdn.lifeapp.pingan.com.cn/cmsinfo/upload/prize/8vbpebhs-_-_-1699604523564.png"
            },
            {
                "prizeName": "笔记本电脑",
                "prizeImage": "https://stg1-eco.cdn.lifeapp.pingan.com.cn/cmsinfo/upload/prize/6g4s24vq-_-_-1685501815353.png"
            },
            {
                "prizeName": "1000优惠券",
                "prizeImage": "https://stg1-eco.cdn.lifeapp.pingan.com.cn/cmsinfo/upload/prize/en4s2et7-_-_-1685501848830.png"
            },
            {
                "prizeName": "1000积分",
                "prizeImage": "https://stg1-eco.cdn.lifeapp.pingan.com.cn/cmsinfo/upload/prize/mzaewrgw-_-_-1685442289440.png"
            }
        ]

使用

val gson = Gson()
        val fromJson =
            gson.fromJson<List<PrizeBean>>(json, object : TypeToken<List<PrizeBean>>() {}.type)
        println(fromJson[0].prizeName)
        Log.d(TAG, "initView: ${fromJson[0].prizeName}")

bean类(只要数组里面的json)

data class PrizeBean(
    val prizeImage: String,
    val prizeName: String
)

2.JSONObject,JSONArray

val json="{
"healthEquity": {
"smallTitle": "主标题小字",
"subTitle": "副标题",
"tag": "标签",
"bigTitle": "主标题大字",
"jumpUrl": "跳转链接"
},
"healthArchive": {
"smallTitle": "主标题小字2",
"subTitle": "副标题2",
"tag": "标签2",
"bigTitle": "主标题大字2",
"jumpUrl": "跳转链接2"
}
}"
        val jsonObject=JSONObject(json)
        val healthEquity = jsonObject.getJSONObject("healthEquity")//获取里面的json
        val smallTitle = healthEquity.getString("smallTitle")//里面JSON的某个值
        Log.d(TAG, "getJson: $healthEquity:\n$smallTitle")

3.

4.

5.

6.

2.控件

1.防重复点击

fun View.setOnSafeClickListener(defaultInterval: Int = 1000, onSafeClick: (View) -> Unit) {
    var lastTimeClicked: Long = 0
    setOnClickListener {
        val now = SystemClock.elapsedRealtime()
        if (now - lastTimeClicked >= defaultInterval) {
            lastTimeClicked = now
            onSafeClick(this)
        }
    }
}

2.

3.

4.

5.

6.

3.计算

1.文本长度

val paint = Paint() //创建一个Paint对象
paint.textSize = 20.0f //设置字体大小
val text = "待测量文字待测量文字.........." //要测量的字符串
val width = paint.measureText(text) //获取字符串的宽度

2.

3.

4.

5.

6.

4.储存

1.sharePreference

//获取SharePreference对象
SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
//获取Editor对象
SharedPreferences.Editor editor = sharedPreferences.edit();
//保存数据
editor.putString("name", "张三");
editor.putInt("age", 25);
//提交数据
editor.apply();
//读取数据
String name = sharedPreferences.getString("name","");
int age = sharedPreferences.getInt("age",0);

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.其他

1.

viewBinding {
enabled true
}
2.adb
(1)连接应用商店,观影的设备
①adb connect 172.18.9.121
(2)连接音乐的设备
①adb connect 172.18.25.87
②adb connect 172.18.9.52 :性能差的那个
(3)息屏设置
①adb shell settings put system screen_off_timeout 100000000
(4)查看当前项目的Activity
①adb shell dumpsys window | findstr mCurrentFocus
②Mac:adb shell dumpsys window | grep mCurrentFocus
(5)启动Activity
①adb shell am start -n com.jmgo.appstore/.detail.ui.AppStoreDetailActivity
(6)网络映射到电脑
①adb shell settings put global http_proxy 172.18.14.244:8888
②adb shell settings put global http_proxy :0
(7)卸载
①adb shell pm uninstall com.jmgo.launcher
(8)获取系统版本
①adb shell getprop ro.build.version.release
(9)打开应用
①adb shell am start com.jmgo.arwen
②adb shell am start com.jmgo.appstore
3.Android studio快捷键
(1)Mac
①Control+shift+J:可以让代码上移动
(2)Windows

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

4.遇到的问题

1.

2.

3.

4.

5.

6.

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值