Android的 - 默认的按钮样式样式、按钮、Android

2023-09-05 05:50:39 作者:笑到面瘫

问: 我在哪里可以找到默认样式的XML与十六进制值$ C $颜色CS?

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

我在寻找样式按钮样式等默认样式巫婆影响像TextViews方面,按钮等等(如果你不改变方面的风格)

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)

我抬头一看&LT; instalation_folder&GT; \ Android的SDK \平台\ android-&LT; versio&GT; \ DATA \水库\值和<instalation_folder>\android-sdk\platforms\android-<version>\data\res\colors但我没有真正找到了我要找的东西。

I looked up in <instalation_folder>\android-sdk\platforms\android-<versio>\data\res\values and <instalation_folder>\android-sdk\platforms\android-<version>\data\res\colors but I didn't actually find what I was looking for.

希望我的问题是清楚的。

Hope my question is clear.

由于低信誉我不能回答这个问题呢。这里有答案

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

答案

通过一个有点谷歌上搜索,我发现按钮样式实际上是Widget.Button - 造型的Andr​​oid为默认设置

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

这是如何工作的:

正如我所说的按钮样式风格accualy在定义\ Android的SDK \平台的Widget.Button式\ android-&LT;版&GT; \ DATA \水库\值\ styles.xml 。背景设置为: @android:绘制/ btn_default \ Android的SDK \平台\ android-&LT;版&GT; \ DATA \水库\绘制\ btn_default.xml 定义按钮,选择的背景色。颜色实际上取决于按钮的状态。默认的颜色设置为 @绘制/ btn_default_normal 有了一点搜索,我发现,这btn_default_normal为png位于 \ Android的SDK \平台图像\ android-&LT;版&GT; \ DATA \水库\绘制-MDPI As I said 'buttonStyle' style is accualy 'Widget.Button' style defined in \android-sdk\platforms\android-<version>\data\res\values\styles.xml. Background is set to: @android:drawable/btn_default \android-sdk\platforms\android-<version>\data\res\drawable\btn_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-sdk\platforms\android-<version>\data\res\drawable-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有主题。一个主题基本上定义的样式应用到哪些部件。 因此,我们的第一步就是要找到默认的Andr​​oid主题。

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的SDK \平台\ Android为15 \ DATA \水库\值\的themes.xml

在此主题文件,搜索按钮

您会发现这样的事情:

<!-- 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.

所有默认的A​​ndr​​oid风格在文件中定义的 Android的SDK \平台\ Android为15 \ DATA \水库\值\ styles.xml

All default Android style are defined in the file android-sdk\platforms\android-15\data\res\values\styles.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>

有趣的行是:

The interesting line is:

&LT;项目名称=机器人:背景&GT; @android:绘制/ btn_default&LT; /项目&GT;

这意味着,有一个叫绘制 btn_default 设置按钮的背景。

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

现在,我们需要找到一个名为 btn_default。*在中绘制一个文件夹 Android的SDK \平台\ Android为15 \数据\ RES

Now we need to find a file named btn_default.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.

这可以是一个形象(不太可能)或类似 btn_default.xml XML文件。

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

在一点点的搜索,你会发现文件 Android的SDK \平台\ Android为15 \ DATA \水库\绘制\ btn_default.xml

After a little bit searching you will find the file android-sdk\platforms\android-15\data\res\drawable\btn_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>

现在,你必须明白,这是一个选择器绘制(许多绘制类型中的一种)。 这个选择选择不同的背景的基础上,按钮的状态。例如,如果按钮被pressed,它具有不同的背景

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.

&LT;项目安卓state_enabled =真正的机器人:可绘制=@可绘制/ btn_default_normal/&GT;

它应用了一个名为绘制 btn_default_normal

It applies a drawable called btn_default_normal.

现在,我们需要找到这个可绘制的。

Now we need to find this drawable.

此外,我们需要找到一个名为 btn_default_normal。*在 在绘制文件夹中的一个Android的SDK \平台\ Android为15 \ DATA \ RES

Again, we need to find a file named btn_default_normal.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.

这可能是一次无论是图片还是喜欢 btn_default_normal.xml 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.