开发者

Android Set ImageView image src in Style

开发者 https://www.devze.com 2023-03-17 13:24 出处:网络
I need to set the ImageView\'s src within my style开发者_Go百科, but I cant find a good example of anyone doing this and when I try the below code, it crashes the app.

I need to set the ImageView's src within my style开发者_Go百科, 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号