androidstudioThe'kotlin-android-extensions'Gradlepluginisnolongersupported
创始人
2024-10-11 18:30:56
0

在android studio中使用'kotlin-android-extensions' Gradle插件不再支持,解决方法是使用findViewById()或ViewBinding。

当使用kotlin-android-extensions插件时,可以通过以下代码实现findViewById()的自动导入:

import kotlinx.android.synthetic.main.activity_main.*

现在,可以通过以下方式替代使用插件:

1.使用findViewById():

val textView = findViewById(R.id.textView)

2.使用ViewBinding:

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    binding.textView.text = "Hello World"
}

需要注意的是,使用ViewBinding需要在build.gradle文件中添加以下依赖:

android {
    ...
    buildFeatures {
        viewBinding = true
    }
}

dependencies {
    ...
    implementation 'com.google.android.material:material:1.4.0'  // 只是举例
}

相关内容

热门资讯

透视app!模拟器打开hhpo... 透视app!模拟器打开hhpoker,wepoker辅助分析器(透视)专业教程(有挂分析)-哔哩哔哩...
有玩家发现!hhpoker脚本... 有玩家发现!hhpoker脚本,wepoker安装教程(透视)解密教程(有挂详细)-哔哩哔哩1、点击...
透视有挂!wepoker辅助工... 透视有挂!wepoker辅助工具,xpoker怎么辅助(透视)总结教程(证实有挂)-哔哩哔哩1、用户...
透视真的!佛手在线大菠萝技巧,... 透视真的!佛手在线大菠萝技巧,wejoker透视方法(透视)推荐教程(发现有挂)-哔哩哔哩1、该软件...
今天上午!wepoker有透视... 今天上午!wepoker有透视吗,we-poker辅助软件教程(透视)详细教程(有挂教学)-哔哩哔哩...
最新消息!wepoker永久免... 最新消息!wepoker永久免费脚本,wepoker辅助器下载(透视)专业教程(有挂总结)-哔哩哔哩...
此事备受玩家关注!有哪些免费的... 此事备受玩家关注!有哪些免费的wpk辅助码,xpoker怎么辅助(透视)了解教程(有挂方略)-哔哩哔...
此事引发网友热议!wepoke... 此事引发网友热议!wepoker好友助力码,wepoker怎么买辅助(透视)揭幕教程(确实有挂)-哔...
透视总结!哈糖大菠萝软件下载,... 透视总结!哈糖大菠萝软件下载,htx矩阵wepoker辅助(透视)解迷教程(有挂猫腻)-哔哩哔哩该软...
据目击者称!wepoker私人... 据目击者称!wepoker私人局辅助,wejoker私人辅助软件(透视)关于教程(有挂方式)-哔哩哔...