【发布时间】:2016-07-01 14:52:12
【问题描述】:
我正在努力学习 Android 应用程序源的结构。我在 Android Studio 中创建了一个新项目。我想使用材料设计的最新功能,此时我不考虑与早期 Android 版本的兼容性。所以我选择了最低 SDK - “API 21: Android 5.0 (Lollipop)”。然后我选择了“全屏活动”。第一个例外是“渲染问题。找不到以下类:android.support.v7.internal.app.WindowDecorActionBar”,当我尝试打开activity_fullscreen.xml 时。在 build.gradle 中,我从依赖项中删除了最后两行:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
然后我得到一个构建错误:
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
我将“styles.xml”配置为使用 Material 主题而不是 "Theme.AppCompat.Light.DarkActionBar"
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
</style>
但仍然存在一个错误:
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.ActionBar'.
在操作栏样式定义中
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
我不知道如何在没有支持库的情况下设置操作栏。为什么我的项目确实需要它?我阅读的文档仅描述了 AppCompat 的操作栏设置。还是 Material 主题根本不提供操作栏?既然我选择了最低 SDK 21,为什么源代码中存在 appcompat-v7 引用?我真的很困惑,因为我什至无法构建一个最简单的项目。
【问题讨论】:
标签: android android-actionbar material-design android-5.0-lollipop