我遇到了类似的问题...我的 Eclipse 工作区中有两个项目,它们都基于 Android 4.2 jar。一个具有 minSdkVersion="8" 和 targetSdkVersion="17" 并且它的样式引用buttonBarStyle
和buttonBarButtonStyle
名称都很好。另一个项目使用相同的清单设置,并且由于错误而无法构建:
No resource found that matches the given name: attr 'buttonBarStyle'.
No resource found that matches the given name: attr 'buttonBarButtonStyle'.
当我看到@dead's
有关需要attrs.xml
文件的评论时,我检查并确定,无法编译的项目缺少该文件。我认为工作项目是使用 Eclipse Android 应用程序项目向导生成的,而另一个是手动创建的。
的内容res/values/attrs.xml
:
<resources>
<!--
Declare custom theme attributes that allow changing which styles are
used for button bars depending on the API level.
?android:attr/buttonBarStyle is new as of API 11 so this is
necessary to support previous API levels.
-->
<declare-styleable name="ButtonBarContainerTheme">
<attr name="buttonBarStyle" format="reference" />
<attr name="buttonBarButtonStyle" format="reference" />
</declare-styleable>
</resources>
的内容res/values/colors.xml:
<resources>
<color name="black_overlay">#66000000</color>
</resources>
以及三个样式文件:
1) res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level
can go here. -->
</style>
<style name="ButtonBarButton" />
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">@android:drawable/bottom_bar</item>
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
<item name="buttonBarStyle">@style/ButtonBar</item>
<item name="buttonBarButtonStyle">@style/ButtonBarButton</item>
</style>
<style name="ContentText">
<item name="android:textColor">#0000ff</item>
<item name="android:textSize">50sp</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
2) res/values-v11/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
<style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
<style name="FullscreenTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="buttonBarStyle">?android:attr/buttonBarStyle</item>
<item name="buttonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
</resources>
3) res/values-v14/styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>