【发布时间】:2019-01-31 16:42:39
【问题描述】:
尝试了许多解决方案,但没有任何帮助
参考:Failed to find style 'coordinatorLayoutStyle' in current theme
但没有帮助
渲染问题:
在当前主题中找不到样式“coordinatorLayoutStyle”
提示:尝试刷新布局。
我的项目的build.gradle文件是:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块:应用程序
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "*****"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0-alpha1'
}
主要活动 XML 代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:navigationIcon="@drawable/ic_menu"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:fabAttached="true"
app:backgroundTint="@color/colorPrimary"
app:fabCradleVerticalOffset="12dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/bar"/>
</android.support.design.widget.CoordinatorLayout>
为什么我不将已编译的 SDK 版本 28 更改为 27 bcz 我想使用底部应用栏
Bottom App Bar Material Design
【问题讨论】:
-
把这个库
implementation 'com.android.support:design:27.1.1'也添加到你的module:app中,分别对应你的sdk -
也许这与最新的支持库版本有关,尽管我不太确定。所以尝试将当前版本替换为 27.1.1 并查看它是否有效。 compileSdkVersion 27 targetSdkVersion 27 和 implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1'
-
当我改变了设计和适用的版本时
-
错误:找不到资源样式/Widget.MaterialComponents.BottomAppBar(又名 *.appbar:style/Widget.MaterialComponents.BottomAppBar)。消息{kind=ERROR, text=error: resource style/Widget.MaterialComponents.BottomAppBar (aka **.appbar:style/Widget.MaterialComponents.BottomAppBar) not found., sources=[/home/android/Desktop/Android Studio Projects /Appbar/app/src/main/res/layout/activity_main.xml:10],原始消息=,工具名称=Optional.of(AAPT)}
-
发生这种情况是因为 Material Components 尚未发布依赖版本 27 下的新版本。因此,如果您想访问最新的更改,您必须将您想要的材料组件库部分直接复制到您的项目中。
标签: java android android-coordinatorlayout android-appbarlayout