Error: Ошибка: ресурс не найден, который соответствует указанному имени: attr 'buttonBarButtonStyle' - программирование
Подтвердить что ты не робот

Error: Ошибка: ресурс не найден, который соответствует указанному имени: attr 'buttonBarButtonStyle'

Я пишу тему в файле styles.xml, как показано ниже

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <!-- Root styles that vary by API level -->
<style name="FrameworkRoot.Theme" parent="Theme.Sherlock.Light.DarkActionBar">
    <!-- API 11+ (compatibility) -->
    <item name="buttonBarStyle">@style/Compat.ButtonBar</item>
    <item name="buttonBarButtonStyle">@style/Compat.ButtonBarButton</item>
    <item name="indeterminateProgressStyle">@style/Compat.IndeterminateProgress</item>
    <!-- API 14+ (compatibility) -->
    <item name="listPreferredItemPaddingLeft">@dimen/compat_list_preferred_item_padding_left</item>
    <item name="listPreferredItemPaddingRight">@dimen/compat_list_preferred_item_padding_right</item>
    <item name="listPreferredItemHeightSmall">@dimen/compat_list_preferred_item_height_small</item>
</style>

но получите ошибку: Ошибка: ресурс не найден, который соответствует указанному имени: attr 'buttonBarStyle'.

Получаю код из google io2012. И моя, и вся ее база

    <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

Я могу скомпилировать исходный код google io2012, но не мой. так странно. кто-нибудь знает почему? или имеют тот же вопрос?

4b9b3361

Ответ 1

buttonBarStyle для версий 11 и выше, как вы заявляете в своем SDK, но используете android:minSdkVersion="8". Разве это не должно работать для android:minSdkVersion="11"?

Ответ 2

У меня была аналогичная проблема... У меня есть два проекта в рабочей области Eclipse, как на базе Android 4.2. Один имеет 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, а другой был создан вручную.

Содержимое 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>

Ответ 4

Убедитесь, что вы включили AppCompat. Это проект библиотеки. Вы должны ссылаться на проект библиотеки в своем проекте андроида.

https://developer.android.com/tools/support-library/setup.html

Проверьте тему Добавление библиотек с ресурсами.

Ответ 5

Была та же проблема, что и у вас:

my build.gradle файл:

android {
compileSdkVersion 25
buildToolsVersion "27.0.1"
defaultConfig {
    applicationId "com.whatever"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}

то, что я сделал в папке "Значения", добавил файл attrs.XML с этими кодами в нем:

<declare-styleable name="ButtonBarContainerTheme">
    <attr name="metaButtonBarStyle" format="reference" />
    <attr name="metaButtonBarButtonStyle" format="reference" />
</declare-styleable>

теперь я не вижу жалоб!

Ответ 6

Я получал такую ​​же ошибку.... удалил папки в

C:\Users \.android\build-cache\Хэш Количество папок, например. 4eaccf0d162ec009b115c7e0ff4f542f8d2a663b\

и он работал как прелесть....