2011-07-06 19 views
12

ImageViewのsrcを自分のスタイル内に設定する必要がありますが、これを行う人の良い例を見つけることができず、以下のコードを試してみるとアプリケーションがクラッシュします。Android Set ImageView image src in Style

<ImageView android:src="@style/TitleBarImage"></ImageView> 

<style name="TitleBarImage">  
    <item name="android:layout_width">wrap_content</item>  
    <item name="android:layout_height">wrap_content</item>  
    <item name="android:src">@drawable/whiteButton</item> 
</style> 

これは簡単です。何がありますか?

答えて

15

あなたのXMLが正しくありません。

<ImageView style="@style/TitleBarImage" /> 

とのstyles.xml:

<style name="TitleBarImage">  
    <item name="android:layout_width">wrap_content</item>  
    <item name="android:layout_height">wrap_content</item>  
    <item name="android:src">@drawable/whiteButton</item> 
</style> 
+0