如何将样式应用于 Android 应用程序的所有按钮 [英] How do I apply a style to all buttons of an Android application

查看:33
本文介绍了如何将样式应用于 Android 应用程序的所有按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个样式应用于我的整个应用程序:

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

在我的styles.xml中:

And in my 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>

但是没有应用样式.

如果我只是在 ApplicationStyle - Item 中使用了假名称,我很抱歉,但我不知道在哪里寻找对象名称,只是假设,android:button 适用于所有按钮.

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.

推荐答案

对于 Android 样式,请参考 Android 在 R.attr.在这种情况下,您似乎想要引用 android:按钮样式.我认为这会奏效:

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:

<style name="ApplicationStyle" parent="android:Theme">
  <item name="android:buttonStyle">@style/CKButton</item>
</style>

这篇关于如何将样式应用于 Android 应用程序的所有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆