Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Set ImageView image src in Style

I need to set the ImageView's src within my style, but I cant find a good example of anyone doing this and when I try the below code, it crashes the app.

<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> 

This should be simple. What gives?

like image 279
Jesse Avatar asked Jul 06 '11 14:07

Jesse


1 Answers

Your xml is incorrect:

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

And 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> 
like image 120
louiscoquio Avatar answered Nov 15 '22 14:11

louiscoquio