我的 ImageButton
似乎不受样式文档中设置的参数的影响,但是当我以完全相同的方式定义其样式时,其他 Button
会受到影响。
这是我的 styles.xml 的压缩版本:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:buttonStyle">@style/Button</item>
<item name="android:imageButtonStyle">@style/ImageButton</item>
</style>
<style name="Button" parent="@android:style/Widget.Button">
<item name="android:background">@color/icons</item>
</style>
<style name="ImageButton" parent="@android:style/Widget.ImageButton">
<item name="android:background">@color/icons</item>
</style>
当使用这些样式时(我已经尝试过与其他项目一起使用,但似乎都不起作用),普通的 Button
将采用 @color/icons
的颜色,但 ImageButton
则不会。当使用 style="@style/ImageButton"
单独设置样式时,它们也不会受到影响,但是,如果我直接在每个按钮上使用 android:background="@color/icons"
设置背景,它确实会产生影响。
最佳答案
使用
style="@style/ImageButton"
在你的按钮主体中,例如:`
<Button
style="@style/button_theme"
android:text="Sign In"
android:id="@+id/id" />`
这是按钮样式
<style name="button_theme">
<item name="android:background">@drawable/button_shape</item>
<!--<item name="android:padding">5dp</item>-->
<item name="android:textColor">#ffffff</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
关于java - ImageButtons 不从主题样式获取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36296813/