[英]Android - default button style
问题:在哪里可以找到带有十六进制颜色代码的默认样式xml?
我正在寻找Style'buttonStyle'和其他默认样式影响像TextViews,Buttons等方面(如果你不改变方面的风格)
我抬头看了<instalation_folder>\\android-sdk\\platforms\\android-<versio>\\data\\res\\values
和<instalation_folder>\\android-sdk\\platforms\\android-<version>\\data\\res\\colors
但是我没有实际上找不到我要找的东西。
希望我的问题很明确。
回答
通过一些谷歌搜索,我发现'buttonStyle'实际上是'Widget.Button' - 使用默认设置Android的样式
这是它的工作原理:
\\android-sdk\\platforms\\android-<version>\\data\\res\\values\\styles.xml
定义的'Widget.Button'样式。 背景设置为: @android:drawable/btn_default
\\android-sdk\\platforms\\android-<version>\\data\\res\\drawable\\btn_default.xml
将按钮的背景颜色定义为选择器。 颜色实际上取决于按钮的状态。 默认颜色设置为@drawable/btn_default_normal
\\android-sdk\\platforms\\android-<version>\\data\\res\\drawable-mdpi
png图像 我发现它有点令人困惑,但我希望它会帮助某人,也许......
了解Android风格的工作原理可能有点混乱。
基于一个例子,我将尝试解释基本工作流程的方式。
假设您想知道按钮的默认背景是什么。 这可以是简单的颜色(不太可能)或可绘制的(有许多不同类型的可绘制的)。
Android有主题。 主题基本上定义了哪个样式应用于哪个小部件。 因此,我们的第一步是找到默认的android主题。
你可以在android-sdk\\platforms\\android-15\\data\\res\\values\\themes.xml
下找到它
在此主题文件中,搜索button
。
你会发现这样的事情:
<!-- Button styles -->
<item name="buttonStyle">@android:style/Widget.Button</item>
这意味着主题将样式Widget.Button
应用于按钮。
好的,现在让我们找到风格Widget.Button
。
所有默认的Android风格都在文件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>
有趣的是:
<item name="android:background">@android:drawable/btn_default</item>
这意味着有一个名为btn_default
的drawable设置为按钮背景。
现在我们需要在android-sdk\\platforms\\android-15\\data\\res
下的一个可绘制文件夹中找到一个名为btn_default.*
的文件。
这可以是图像(非常不可能),也可以是像btn_default.xml
这样的xml文件。
经过一点点搜索,你会发现文件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>
现在您必须了解这是一个可绘制的选择器(许多可绘制类型之一)。 此选择器根据按钮状态选择不同的背景。 例如,如果按下按钮,则它具有不同的背景。
不,让我们看看默认状态。
<item android:state_enabled="true" android:drawable="@drawable/btn_default_normal" />
它应用了一个名为btn_default_normal
的drawable。
现在我们需要找到这个可绘制的。
同样,我们需要在android-sdk\\platforms\\android-15\\data\\res
下的一个可绘制文件夹中找到一个名为btn_default_normal.*
的文件。
这可以是图像或像btn_default_normal.xml
这样的xml文件。
您将在不同的可绘制文件夹中找到多个名为“btn_default_normal.9.png”的文件,以用于不同的分辨率。
:)现在您知道btn_default_normal.9.png
被设置为按钮背景。
在XML中声明时,可以找到android小部件的默认样式:
style="@android:style/Widget.Button" - standard Button
style="@android:style/Widget.TextView" - standard TextView
例如,这是默认按钮的样式:
<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>
默认按钮的背景:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_default_normal" android:state_enabled="true" android:state_window_focused="false"/>
<item android:drawable="@drawable/btn_default_normal_disable" android:state_enabled="false" android:state_window_focused="false"/>
<item android:drawable="@drawable/btn_default_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_default_selected" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="@drawable/btn_default_normal" android:state_enabled="true"/>
<item android:drawable="@drawable/btn_default_normal_disable_focused" android:state_focused="true"/>
<item android:drawable="@drawable/btn_default_normal_disable"/>
</selector>
您可以在任何图形编辑器的帮助下获得默认颜色:路径默认按钮NinePatch .. \\ android-sdk \\ platforms \\ android-13 \\ data \\ res \\ drawable-hdpi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.