How to apply an style to all ImageButtons in Android?

故事扮演 提交于 2019-12-04 14:16:14

Change your BtnPressed style to this:

<style name="BtnPressedStyle" parent="Widget.ImageButton">
  <item name="android:background">@drawable/btn_default</item>
</style>

Define an application-wide theme/style:

<style name="MyTheme" parent="android:Theme">
   <item name="android:imageButtonStyle">@style/BtnPressedStyle</item>
</style>

Then apply it to your application tag of the manifest:

<application theme="@style/MyTheme" ... />

Let me know if this works, I adapted it from my code that overrides application-wide button style, but ImageButton should work just as well.

You can also spend about 5 minutes in your IDE (notepad++ will do) and search and replace ImageView on xmls , and a little snippet for image views generated in code. I don't think it's so wrong, and will help you to maintain the app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!