Kotlin开发Android之基础问题记录

1、Kotlin中如何直接通过组件id来操作组件?

解决方案:在build.gradle中添加对相应插件的使用即可。

复制代码
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

2、Kotlin中Button设置背景颜色没有效果。

解决方案:在res->values->themes.xml文件中修改如下代码:

复制代码
<style name="Theme.MyKotlinDemo" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">

3、Kotlin中如何使用静态类或者静态方法?

解决方案:

复制代码
//静态方法
companion object {
    fun actionStart(context: Context) {
        var intent = Intent(context, ServiceIpActivity::class.java)
        context.startActivity(intent)
    }
}

//静态类
object SPUtils {...}

4、Kotlin中EditText的赋值问题。

复制代码
ServiceIP_etServiceIP.text = Editable.Factory.getInstance().newEditable(hostIp)
相关推荐
砖厂小工44 分钟前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心1 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心2 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker4 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴4 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜1 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker1 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95271 天前
Andorid Google 登录接入文档
android
黄林晴1 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack
冬奇Lab2 天前
Android触摸事件分发、手势识别与输入优化实战
android·源码阅读