簡體   English   中英

找不到與給定名稱Xamarin Android匹配的資源

[英]No Resource found that matches the given name Xamarin Android

無論我使用哪種資源或使用它,我總是在themes.xml文件中收到錯誤“找不到與給定名稱匹配的資源”錯誤。 即使資源在其他地方也有效。

這是一些代碼:

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="Theme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
        <item name="android:actionOverflowButtonStyle">@style/ActionBarOverflowStyle</item>
    </style>

    <!-- ActionBar styles -->
    <style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#008A3D</item>
    </style>

    <style name="ActionBarOverflowStyle" parent="@android:style/Widget.Holo.ActionButton.Overflow">
        <item name="android:src">@drawable/OverflowIcon</item>
    </style>


    <!--Dialog styles-->
    <style name="DialogStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#008A3D</item>
    </style>
</resources>

我刪除了項目節點以檢查我是否可以在代碼中使用該資源。 證明它有效; 沒錯誤:

經過谷歌搜索和擺弄幾個小時后,我發現問題是由於我在文件名中使用大寫字符,這在其他任何地方都可以正常工作。 這可能是Android的可怕行為,也可能是Xamarin中的錯誤。

對於因其他原因發現此問題的其他人:

每當我在VS 2017中復制重命名可繪制資源時,它都會更改“構建操作”。

仔細檢查您的資源,確保正確設置Build Action。 就我而言,它需要是'AndroidResource'

從項目中刪除圖像,清理項目,添加正確重命名的圖像(一旦添加到項目中,不要嘗試重命名圖像)。 應該完美。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM