2016-04-08 4 views
1

ボタンのリストでGUIを作成しました。InflateException:無効なボタンのセレクタ

これらのボタンの一部が無効にすることができると私はこのセレクタ(color/selector_fav_button.xml)を添加した理由で異なる色で表示されるべきである:私はスタイル属性(値/スタイルで、このセレクタを参照

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false" android:color="@color/button_favorite_disabled" /> 
    <item android:color="@color/button_default"/> 
</selector> 

.xml):

<style name="favButtonStyle"> 
     <item name="android:textColor">@color/primary_text</item> 
     <item name="android:textSize">@dimen/textView_default_textsize_small</item> 
     <item name="android:background">@color/selector_favorite_button</item><!--Adding this line causes a crash--> 
</style> 

とスタイルは、私のボタンで参照されています。

<Button 
    android:id="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/fav_button_item_height" 
    android:text="@{favBtn.displayText}" 
    android:enabled="@{favBtn.isEnabled}" 
    style="@style/favButtonStyle" 
/> 

@ color/any_color_but_not_a_selectorのような色を割り当てても問題ありません。セレクタを参照する行の周りにコメントを置くと、すべてが再び機能します(色を除いて;))。

私はそれがクラッシュしandroid.view.InflateException残しコメントせずに私のアプリを実行する場合:バイナリXMLファイルのライン#8:エラー膨張クラスボタン

EDIT:は エラーがここにoccures:

ListitemFavBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.listitem_favBtn, parent, false); 

答えて

2

セレクタはres/drawable .This

<item name="android:background">@color/selector_favorite_button</item> 

shoulにする必要がありますd be

<item name="android:background">@drawable/selector_favorite_button</item> 

セレクタはカラーリソースではありません。

+0

それでも同じエラーがスローされる – Karl

+0

データバインディングの問題 –

関連する問題