如何将样式应用于Android中的所有ImageButton? [英] How to apply an style to all ImageButtons in Android?
本文介绍了如何将样式应用于Android中的所有ImageButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中具有以下样式.
I have the following style in my application.
<style name="BtnPressed">
<item name="android:background">@drawable/btn_default</item>
</style>
现在,我要将其应用于应用程序中的所有ImageButtons
.我试图使用
Now I want to apply that to all the ImageButtons
in my application. I tried to use the solution mentioned in this question but it did not work. I'm using API-7.
推荐答案
将BtnPressed样式更改为此:
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" ... />
让我知道这是否可行,我从覆盖了应用程序级按钮样式的代码中对其进行了改编,但是ImageButton应该也能正常工作.
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.
这篇关于如何将样式应用于Android中的所有ImageButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文