按钮的默认背景颜色是什么。请以html颜色代码的形式告诉我背景颜色。
谢谢!
Android基本上有不同的主题。主题决定了应用到小部件的样式。主题在路径下的themes.xml文件中定义
android-sdk\platforms\android-15\data\res\values\themes.xml
现在我们需要找到在themes.xml 中定义的Button 的样式。当您使用它时,您会发现类似:
<!-- Button styles -->
<item name="buttonStyle">@android:style/Widget.Button</item>
这意味着主题将样式 Widget.Button 应用于按钮。现在寻找风格
小部件.按钮
这种风格将在
android-sdk\platforms\android-15\data\res\values\styles.xml
您会在 Widget.Button 的 theme.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\platforms\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\platforms\android-15\data\res 下的一个可绘制文件夹中找到一个名为 btn_default_normal.* 的文件。
这又可以是图像或 xml 文件,例如 btn_default_normal.xml。
现在,您将在不同的可绘制文件夹中找到多个名为“btn_default_normal.9.png”的文件,用于不同的分辨率。
所以现在您知道其中没有包含特定十六进制代码的颜色。它是一个 9 补丁图像 (btn_default_normal.9.png)。
希望这可以帮助。
您可以将背景颜色设置为@null。
简单 - 转到布局\查看代码并删除 android:#color 代码;-)