JDChi / Android_Code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

相关说明

Compose

基本依赖

Adding Jetpack Compose to your app 在 app 的 build.gradle 文件里增加 Compose 的依赖:

android {
    buildFeatures {
        // Enables Jetpack Compose for this module
        compose true
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.3.2"
    }
}

dependencies {
    implementation 'androidx.activity:activity-compose:1.6.0'
    implementation 'androidx.compose.material:material:1.2.1'
}

要注意下 Compose 与 Kotlin 之间的版本关系。Compose to Kotlin Compatibility Map

UI 预览

增加依赖:

dependencies {
    // Tooling support (Previews, etc.)
    implementation 'androidx.compose.ui:ui-tooling:1.2.1'
}

在想要预览的地方增加 @Preview 注解:

    @Preview
    @Composable
    private fun takeAScreenshot() {
        Button(onClick = { Toast.makeText(this, "hello", Toast.LENGTH_SHORT).show() }) {

        }
    }

About


Languages

Language:Kotlin 100.0%