简体   繁体   English

活动中的视图绑定与膨胀和根有一些问题

[英]View binding in activity have some issues with inflate and root

I have issues with view binding in android studio with inflate and root.我在 android 工作室中使用 inflate 和 root 进行视图绑定时遇到问题。 below of inflate and root is a redline. inflate 和 root 下面是一条红线。

I also write view binding modules in build.gradle. This is my build.gradle codes.我也在build.gradle写了视图绑定模块。这是我的build.gradle代码。

defaultConfig {
    applicationId "com.wallpaper.view"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}
buildFeatures {
    viewBinding = true
}

dependencies {依赖关系{

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

And this is my activity codes.这是我的活动代码。

class MainActivity : AppCompatActivity() {

    lateinit var binding:ActivityMainBinding

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

I have a read line below inflate and root.我在 inflate 和 root 下面有一个 read 行。

How can I fix this?我怎样才能解决这个问题?

I realize some of the modules in my build.gradle was not updated, Then I updated modules and issue or red line below of inflate, and root was gone.我意识到我的 build.gradle 中的某些模块没有更新,然后我更新了模块并在 inflate 下发出或红线,root 不见了。 There are the codes I updated.有我更新的代码。

from this由此

android {
namespace 'com.wallpaper.view'
compileSdk 32

defaultConfig {
    applicationId "com.wallpaper.view"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

To this对此

android {
namespace 'com.wallpaper.view'
compileSdk 33

defaultConfig {
    applicationId "com.wallpaper.view"
    minSdk 21
    targetSdk 33
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

I just update the version of compileSdk and targetSdk.我只是更新了compileSdk和targetSdk的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM