按钮的默认背景颜色是什么。请以html颜色代码的形式告诉我背景颜色。
谢谢!
发布于 2013-03-03 11:40:14
Android基本上有不同的主题。主题决定了要应用于小部件的样式。主题在路径下的themes.xml文件中定义
android-sdk\platforms\android-15\data\res\values\themes.xml
现在我们需要找到在themes.xml中定义的按钮的样式。当你使用它时,你会发现类似这样的东西:
<!-- Button styles -->
<item name="buttonStyle">@android:style/Widget.Button</item>这意味着主题将样式Widget.Button应用于按钮。现在来看一下样式
Widget.Button
此样式将在
android-sdk\platforms\android-15\data\res\values\styles.xml您将在Widget.Button的themes.xml中找到类似以下内容的内容
<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的可绘制文件被设置为按钮背景。
现在我们需要在android-sdk\platform\android-15\data\res下的一个可绘制文件夹中找到一个名为btn_default.*的文件。
稍微搜索一下,您就会找到文件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" />
这是一个可绘制的选择器。此选择器根据按钮状态选择不同的背景。例如,按下的按钮将具有与未按下的按钮不同的背景。
因此,我们需要查看Button的默认(未按下)状态。
<item android:state_enabled="true" android:drawable="@drawable/btn_default_normal" />因此,在这里应用以下可绘制的代码:
btn_default_normal现在我们需要在android-sdk\platform\android-15\data\res下的一个可绘制文件夹中找到一个名为btn_default_normal.*的文件。
这也可以是图像或btn_default_normal.xml之类的xml文件。
现在你会在不同的可绘制文件夹中找到多个名为'btn_default_normal.9.png‘的文件,具有不同的分辨率。
现在你知道了,这里没有包含特定十六进制代码的颜色。这是一个9补丁图像(btn_default_normal.9.png)。
希望这能有所帮助。
发布于 2013-03-03 13:20:44
只需将背景颜色设置为@null即可。
发布于 2014-05-11 12:12:47
简单-转到布局\查看代码并删除android:#color代码;-)
https://stackoverflow.com/questions/15181937
复制相似问题