如何将样式应用于 Android 应用程序的所有按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2410836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I apply a style to all buttons of an Android application
提问by whlk
I have a style applied to my whole application:
我有一个样式应用于我的整个应用程序:
AndroidManifest.xml:
AndroidManifest.xml:
<application android:theme="@style/ApplicationStyle" android:icon="@drawable/icon" android:label="@string/app_name">
And in my styles.xml:
在我的styles.xml中:
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:button">@style/CKButton</item>
</style>
<style name="CKButton" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:layout_margin">0dip</item>
<item name="android:background">#ff0000</item>
</style>
But the style doesn't get applied.
但是样式没有得到应用。
I'm sorry if I just used the false name in the ApplicationStyle
- Item
, but I have no clue where to look for the object names and simply assumed, that android:button
applies to all buttons.
如果我只是在ApplicationStyle
- 中使用了假名称,我很抱歉Item
,但我不知道在哪里寻找对象名称,只是假设,这android:button
适用于所有按钮。
回答by Dan Lew
For Android styles, you reference the preset attributes that Android has laid out in R.attr
. In this case, it looks like you want to to reference android:buttonStyle
. I think this would work:
对于 Android 样式,您引用 Android 在R.attr
. 在这种情况下,您似乎想要引用android:buttonStyle
. 我认为这会奏效:
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:buttonStyle">@style/CKButton</item>
</style>