BottomAppBar 未正确加载

The*_*ler 0 xml android gradle android-layout android-studio

我正在尝试复制这个 BottomAppBar

但无论我遵循什么指南,我能得到的最好的就是这个

我是 Android 开发的完全新手,这让我很抓狂。我检查了创建的全新项目,看看问题是否与我的有关。我煞费苦心地从所有不同的指南中复制了每个可能相关的 Gradle 依赖项,但似乎没有任何效果。

编辑器的自动完成功能可以识别 BottomAppBar 视图及其属性,但它在预览中根本不起作用,只会在应用程序中崩溃。

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.hlag.projecttabletop"
        minSdkVersion 25
        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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.material:material:1.1.0-alpha08'
    testImplementation 'junit:junit:4.12'

}

Run Code Online (Sandbox Code Playgroud)
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.hlag.projecttabletop"
        minSdkVersion 25
        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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.material:material:1.1.0-alpha08'
    testImplementation 'junit:junit:4.12'

}

Run Code Online (Sandbox Code Playgroud)

Son*_*ony 5

您的应用主题应该扩展MaterialComponents主题,而不是AppCompatTheme,

像这样。

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
Run Code Online (Sandbox Code Playgroud)

BottomAppBar 应该包裹在一个 CoordinatorLayout

而你app:fabAlignmentMode的底部应用栏不见了