Android - 默认按钮样式 [英] Android - default button style

查看:29
本文介绍了Android - 默认按钮样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:在哪里可以找到带有十六进制颜色代码的默认样式 xml?

Question: Where can I find default styles xml with hexadecimal codes of colors?

我正在寻找 Style 'buttonStyle' 和其他影响 TextViews、Buttons 等方面的默认样式(如果您不更改方面的样式)

I'm looking for Style 'buttonStyle' and other default styles witch affect aspects like TextViews, Buttons etc (if you dont change the style of aspect)

我在 android-sdkplatformsandroid-data esvaluesandroid-sdk 中查找platformandroid-<version>data escolors 但我实际上没有找到我要找的东西.

I looked up in <instalation_folder>android-sdkplatformsandroid-<versio>data esvalues and <instalation_folder>android-sdkplatformsandroid-<version>data escolors but I didn't actually find what I was looking for.

希望我的问题很清楚.

<小时>由于声誉低,我还不能回答这个问题.这是答案


Due to low reputation I cant answer this question yet. Here is answer

回答

通过一些谷歌搜索,我发现 'buttonStyle' 实际上是 'Widget.Button' -使用默认值设置 Android 样式

With a bit of googling I found 'buttonStyle' is actually 'Widget.Button' - Styling Android With Defaults

这是它的工作原理:

  • 正如我所说,'buttonStyle' 样式是在 android-sdkplatformsandroid-<version>data esvaluesstyles.xml 中定义的 accuay 'Widget.Button' 样式.背景设置为:@android:drawable/btn_default
  • android-sdkplatformsandroid-data esdrawabletn_default.xml 将按钮的背景颜色定义为选择器.颜色实际上取决于按钮的状态.默认颜色设置为 @drawable/btn_default_normal
  • 通过一些搜索,我发现 btn_default_normal 是位于 android-sdkplatformsandroid-<version>data esdrawable-mdpi
  • 的 png 图像
  • As I said 'buttonStyle' style is accualy 'Widget.Button' style defined in android-sdkplatformsandroid-<version>data esvaluesstyles.xml. Background is set to: @android:drawable/btn_default
  • android-sdkplatformsandroid-<version>data esdrawabletn_default.xml defines background color of button as selector. Color actually depends on button's state. Default color is set to @drawable/btn_default_normal
  • With a bit of searching I found, that btn_default_normal is png image located in android-sdkplatformsandroid-<version>data esdrawable-mdpi

我觉得这有点令人困惑,但我希望它会帮助某人,也许......

I find it a bit confusing, but I hope it will help someone, maybe...

推荐答案

了解 Android 样式的工作原理可能有点混乱.

Understanding how Android styles do work can be a little bit messy.

我将尝试解释基本的工作流程,基于一个例子.

I will try to explain how the basic work flow would be, based on an example.

假设您想知道按钮的默认背景是什么.这可以是简单的颜色(不太可能)或可绘制对象(有许多不同类型的可绘制对象).

Let's assume you want to know what the default background for buttons is. This can be either a simple color (unlikely) or a drawable (there are many different types of drawables).

Android 有主题.主题基本上定义了哪种样式应用于哪个小部件.因此,我们的第一步是找到默认的android主题.

Android has Themes. A theme basically defines which style is applied to which widget. Therefore, our first step is to find the default android theme.

你可以在 android-sdkplatformsandroid-15data esvalues hemes.xml

在这个主题文件中,搜索button.

In this theme file, search for button.

你会发现这样的东西:

<!-- Button styles -->

<item name="buttonStyle">@android:style/Widget.Button</item>

这意味着主题将样式 Widget.Button 应用于按钮.

This means that the theme applies the style Widget.Button to buttons.

好的,现在让我们找到样式Widget.Button.

Ok, now let's find the style Widget.Button.

所有默认的Android样式都定义在文件android-sdkplatformsandroid-15data esvaluesstyles.xml

All default Android style are defined in the file android-sdkplatformsandroid-15data esvaluesstyles.xml

现在搜索Widget.Button

你会发现这样的东西:

<style name="Widget.Button">
    <item name="android:background">@android:drawable/btn_default</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
    <item name="android:textColor">@android:color/primary_text_light</item>
    <item name="android:gravity">center_vertical|center_horizontal</item>
</style>

有趣的一行是:

​​@android:drawable/btn_default

这意味着有一个名为 btn_default 的 drawable 设置为按钮背景.

This means that there is a drawable called btn_default set as button background.

现在我们需要在 android-sdkplatformsandroid-15data es 下的 drawable 文件夹之一中找到一个名为 btn_default.* 的文件.

Now we need to find a file named btn_default.* in one of the drawable folders under android-sdkplatformsandroid-15data es.

这可以是图像(不太可能)或像 btn_default.xml 这样的 xml 文件.

This can be either an image (very unlikely) or a xml file like btn_default.xml.

稍加搜索后你会找到文件android-sdkplatformsandroid-15data esdrawabletn_default.xml

After a little bit searching you will find the file android-sdkplatformsandroid-15data esdrawabletn_default.xml

它包含如下内容:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/btn_default_normal" />
    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/btn_default_normal_disable" />
    <item android:state_pressed="true" android:drawable="@drawable/btn_default_pressed" />
    <item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/btn_default_selected" />
    <item android:state_enabled="true" android:drawable="@drawable/btn_default_normal" />
    <item android:state_focused="true" android:drawable="@drawable/btn_default_normal_disable_focused" />
    <item android:drawable="@drawable/btn_default_normal_disable" />
</selector>

现在你必须明白这是一个选择器可绘制(许多可绘制类型之一).此选择器根据按钮状态选择不同的背景.例如,如果按钮被按下,它会有不同的背景.

Now you have to understand that this is a selector drawable (one of the many drawable types). This selector chooses different backgrounds, based on the buttons state. For example, if the buttons is pressed, it has a different background.

不,让我们看看默认状态.

No let's look at the default state.

<item android:state_enabled="true" android:drawable="@drawable/btn_default_normal"/>

它应用了一个叫做btn_default_normal的drawable.

It applies a drawable called btn_default_normal.

现在我们需要找到这个drawable.

Now we need to find this drawable.

同样,我们需要在 android-sdkplatformsandroid-15data es 下的可绘制文件夹之一中找到一个名为 btn_default_normal.* 的文件.

Again, we need to find a file named btn_default_normal.* in one of the drawable folders under android-sdkplatformsandroid-15data es.

这又可以是图像或 xml 文件,例如 btn_default_normal.xml.

This can be again either an image or a xml file like btn_default_normal.xml.

您会在不同的可绘制文件夹中针对不同的分辨率找到多个名为btn_default_normal.9.png"的文件.

You will find multiple files called 'btn_default_normal.9.png' in different drawable folders for different resolutions.

:) 现在您知道 btn_default_normal.9.png 被设置为按钮背景.

:) Now you know that btn_default_normal.9.png is set as button background.

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

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