2013-02-07 19 views
26

我看到一個我從未見過的錯誤,因爲它阻止了我的一些佈局文件在Eclipse中呈現。它們在運行時渲染良好。Android佈局錯誤:「資源ID <res_id>不是STYLE類型(而不是attr)」

,在圖形佈局編輯器(和我的錯誤日誌)顯示出來的錯誤: 「種源ID 0x1010081不是類型樣式(代替attr)使用」

我在搜索資源ID 0x1010081我的R文件,我無法找到它,所以我猜可能不知何故,我與內置的Android attr有衝突。我還驗證了我的所有樣式屬性都指向了實際樣式,而不是attr。任何幫助讚賞。

這裏是我的完整佈局代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bkg_light" 
    android:padding="@dimen/padding_med" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout_activity" 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/button_height" 
     android:background="@drawable/xml_button" 
     android:padding="@dimen/padding_med" > 

     <TextView    
      style="@style/text_large_bold_white" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:text="@string/activity" /> 

     <TextView 
      android:id="@+id/textView_activity" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="@dimen/margin_med" 
      android:layout_toLeftOf="@+id/textView_arrow_right_start_date" 
      android:text="@string/none_selected"/> 

     <TextView 
      android:id="@+id/textView_arrow_right_start_date" 
      style="@style/arrow_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" /> 
    </RelativeLayout> 

    <!-- kv Duration --> 

    <RelativeLayout 
     android:id="@+id/relativeLayout_duration" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relativeLayout_activity" 
     android:layout_marginTop="@dimen/margin_large" 
     android:background="@drawable/xml_button"> 

     <TextView 
      android:id="@+id/textView_duration" 
      style="@style/text_large_bold_white" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:text="@string/duration_lc" 
      android:paddingLeft="@dimen/padding_med"/> 

     <Spinner 
      android:id="@+id/spinner_duration" 
      android:layout_width="wrap_content" 
      android:layout_height="@dimen/button_height" 
      android:layout_alignParentRight="true" 
      android:entries="@array/array_durations" 
      android:prompt="@string/duration_lc" 
      android:spinnerMode="dropdown" 
      android:clickable="false"/> 
    </RelativeLayout> 

</RelativeLayout> 

這是我的styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="arrow_right"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_xxlarge</item> 
     <item name="android:text">@string/arrow_right</item> 
    </style> 

    <style name="button_blue"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:background">@drawable/selector_button_blue</item> 
     <item name="android:padding">@dimen/padding_med</item> 
    </style> 

    <style name="button_blue_small"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:background">@drawable/selector_button_blue_small</item> 
     <item name="android:padding">@dimen/padding_med</item> 
    </style> 

    <style name="button_dark"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:background">@drawable/selector_button_dark</item> 
     <item name="android:padding">@dimen/padding_med</item> 
    </style> 

    <style name="button_light"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">@color/black</item> 
     <item name="android:background">@drawable/selector_button_light</item> 
     <item name="android:padding">@dimen/padding_med</item> 
    </style> 

    <style name="button_light_small"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">@color/black</item> 
     <item name="android:textSize">@dimen/text_small</item> 
     <item name="android:background">@drawable/selector_button_light</item> 
     <item name="android:padding">@dimen/padding_small</item> 
    </style> 

    <style name="text_small_gray_light"> 
     <item name="android:textSize">@dimen/text_small</item> 
     <item name="android:textColor">@color/gray_light</item> 
    </style> 

    <style name="text_med_bold_gray_light"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_med</item> 
     <item name="android:textColor">@color/gray_light</item> 
    </style>  

    <style name="text_large_bold_white"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_large</item> 
    </style> 

    <style name="text_large_bold_black"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_large</item> 
     <item name="android:textColor">@color/black</item> 
    </style> 

    <style name="text_large_bold_gray_dark"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_large</item> 
     <item name="android:textColor">@color/gray_dark</item> 
    </style> 

    <style name="text_large_bold_gray_light"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_large</item> 
     <item name="android:textColor">@color/gray_light</item> 
    </style> 

    <style name="text_large_bold_white"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">@dimen/text_large</item> 
     <item name="android:textColor">@color/white</item> 
    </style> 

    <style name="text_large_white"> 
     <item name="android:textSize">@dimen/text_large</item> 
     <item name="android:textColor">@color/white</item> 
    </style> 
</resources> 

這是我的自定義theme.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <style name="Theme.P90X" parent="@style/Theme.Sherlock"> 
     <item name="android:textColor">#ffffffff</item> 
    </style> 
</resources> 
+1

你能附上完整的錯誤日誌和你的styles.xml? –

+0

@JustinJasmann:列出styles.xml。唯一我得到的是上面列出的那個。 –

+1

你爲什麼不接受正確的答案? – John

回答

71

我也有這個問題,顯示相同的資源ID。當我將android:spinnerMode更改爲"dialog"時,它消失了,所以我懷疑它不是您的代碼的問題。

該問題的id是指android屬性spinnerStyle。見R.attr

我找到了一個解決方法的文檔,即以

android:spinnerStyle="@android:style/Widget.Spinner.DropDown"更換

android:spinnerMode="dropdown"

+3

這工作完美。謝謝! OP應該認爲你的答案是正確的。 – pmont

+5

注意@android:style/Widget.Spinner.DropDown需要API級別11 –

+1

雖然它也爲我排除了錯誤,但在運行時出現「錯誤膨脹類android.widget.Spinner」。 – Patrick

4

你有沒有試圖改變每個樣式屬性如下所示:

style="?attr/text_large_bold_white" 
+0

我的佈局中的樣式是在styles.xml中定義的自定義樣式。我已在發佈中列出。 –

0

刪除所有style元素,然後逐個添加它們並始終檢查它是否仍呈現。所以你至少可以找出應該指責哪一個。

+0

我嘗試刪除所有風格的標籤,我仍然看到錯誤也許與系統風格有一些衝突? –

+0

您是否有自定義主題,可能會間接添加樣式? – Ridcully

+0

我有一個自定義主題,其父項爲Theme.Sherlock。然而,這很簡單。我已將它添加到發佈中。 –

0

隨着谷歌指向此頁面的這個錯誤,併爲子孫後代着想......

在我的情況下,一時興起,我關閉並重新打開日食和繁榮錯誤消失了,日食渲染預覽沒有任何問題。

雖然我堅信這可能不是所有情況。

如果你覺得你已經完成一切正確,我想,它不會傷害重新啓動日食。

1

由於JulianSymes說,問題是

android:spinnerMode="dropdown" 

他的解決方案(替換爲android:spinnerStyle="@android:style/Widget.Spinner.DropDown")我的手機上運行,​​而不是在我的平板電腦

我的解決方案更簡單:刪掉就行了。

spinnerMode="dropdown"在默認情況下,因此它的unnecesary

相關問題