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)
相关推荐
通玄7 小时前
Jetpack Compose 入门系列(六):Navigation 3 页面导航
android
rocpp10 小时前
Android 多语言切换实战:从 Context 到 Android 13 应用语言适配
android·kotlin
释然小师弟11 小时前
Android开发十年:反思与回顾
android·后端·嵌入式
黄林晴13 小时前
用了这么久 Koin Scope,原来一直都用错了?
android·kotlin
爱勇宝1 天前
我做了一个只用来搜歌词的小 App
android·前端·后端
众少成多积小致巨1 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
唐青枫1 天前
Kotlin Context Parameters 详解:别再把 Logger、事务和配置层层往下传
kotlin
Coffeeee1 天前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker2 天前
5 分钟搞懂 Kotlin DSL
android·kotlin
恋猫de小郭2 天前
AI Agent 开发究竟是啥?如何用 AI 开发 Agent ?深入浅出给你一套概念
android·前端·ai编程