2014-02-20 24 views
0

我試圖爲我的應用程序開發兩個主題,並且根據主題,我需要一個View來使用不同的選擇器。雖然當我創建一個引用來決定使用正確的選擇器時,我得到一個InflationException錯誤。引用選擇器會導致InflationException

這裏是我的attrs.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <declare-styleable name="ReditrTheme"> 
     <attr name="downvoteArrow" format="reference" /> 
     <attr name="upvoteArrow" format="reference" /> 
    </declare-styleable> 

    <declare-styleable name="VoteState"> 
     <attr name="enabled" format="boolean" /> 
    </declare-styleable> 

</resources> 

這裏是我的themes.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <style name="DarkTheme" parent="@android:style/Theme.Holo"> 
     <item name="upvoteArrow">@drawable/upvote_states</item> 
     <item name="downvoteArrow">@drawable/downvote_states</item> 
    </style> 

    <style name="LightTheme" parent="@android:style/Theme.Holo.Light"> 
     <item name="upvoteArrow">@drawable/upvote_states_l</item> 
     <item name="downvoteArrow">@drawable/downvote_states_l</item> 
    </style> 

</resources> 

這裏是我的upvote_states.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.reditr.app"> 

<item android:drawable="@drawable/ic_action_arrow_top_colored" app:enabled="true"/> 
<item style="@drawable/ic_action_arrow_top" app:enabled="false"/> 

</selector> 

這裏是我的upvotes_states_l.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.reditr.app"> 

<item android:drawable="@drawable/ic_action_arrow_top_colored" app:enabled="true"/> 
<item style="@drawable/ic_action_arrow_top_l" app:enabled="false"/> 

</selector> 

downvotes_states.xml和downvotes_states_l.xml與上面的相同,它們只是使用ic_action_arrow_bottom來代替。

最後,這是我的觀點,我試圖以應用參考:

<com.example.views.UpvoteView 
    android:id="@+id/upvote" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:scaleType="fitCenter" 
    android:src="?attr/upvoteArrow" /> 

我試着在網上一些解決方案,但他們總是對我問題有點略有不同,並沒有解決我的問題。

在此先感謝!

回答

0

剛剛意識到我犯的錯誤。在我的states.xml文件中,出於某種原因我使用了style屬性,它應該是android:drawable。