我正在尝试复制this BottomAppBar
但无论我遵循什么指南,都可以得到is this
我是Android开发 Realm 的新手,这让我发疯。我检查了创建的全新项目,以查看问题是否出在我的身上。我辛苦地复制了所有不同指南中可能相关的每一个Gradle依赖项,但似乎没有任何效果。
编辑器的自动完成功能可以识别BottomAppBar View 及其属性,但是在预览中它根本不起作用,只是在应用程序中崩溃。
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'
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.TestActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_gravity="bottom"
android:id="@+id/bottomAppBar"
android:backgroundTint="@color/colorPrimary"
app:navigationIcon="@drawable/ic_drag_handle_black_24dp">
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
最佳答案
您的应用程序主题应扩展MaterialComponents
主题,而不是AppCompatTheme
,
像这样。
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
BottomAppBar
应该包装在CoordinatorLayout
中并且您的底部应用栏缺少
app:fabAlignmentMode