Bas*_*ock 18 android android-layout android-studio android-viewbinding
我目前正在尝试新的 ViewBindings,但我没有让它们工作。我在Android Studio 3.6.1
。我刚刚创建了一个新项目并添加viewBinding.enabled = true
到我的模块中build.gradle
。但是当我尝试访问MainActivityBinding
该类时,它说它无法解析该符号。自动完成找不到任何类似于绑定类的东西。我也尝试过使用 Kotlin 的不同项目,但没有成功。AS4.0
也没有帮助。我需要做什么来生成ViewBinding
类?
我的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
viewBinding {
enabled = true
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)
Joh*_*n G 73
我找不到我的ViewBinding
文件,直到我意识到绑定是以XML
文件(“fragment_home.xml”)而不是类(“HomeFragment.kt”)命名的。所以我找不到他们,HomeFragmentBinding
但我找到了他们FragmentHomeBinding.
我发现将每个 ViewBinding 视为已创建为该 XML 文件的委托的助手单例很有帮助。
(编辑以删除过时的 Gradle 内容)
归档时间: |
|
查看次数: |
8287 次 |
最近记录: |