Reputation: 39
What is the default background color of the button. Please tell me the background color in a form of a html color code.
Thanks!
Upvotes: 2
Views: 8804
Reputation: 1
Simple - go to the layout \ see the code and delete the android:#color code ;-)
Upvotes: 0
Reputation: 3808
Android basically has different themes. Themes decide what style to apply to a widget. The themes are defined in the themes.xml file under the path
android-sdk\platforms\android-15\data\res\values\themes.xml
Now we need to find the style for Button defined in themes.xml. When you for it you will find something like :
<!-- Button styles -->
<item name="buttonStyle">@android:style/Widget.Button</item>
This means that the theme applies the style Widget.Button to buttons. Now look for the style
Widget.Button
This style will be defined in
android-sdk\platforms\android-15\data\res\values\styles.xml
You will find something like below in themes.xml for 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>
Now what is of importance in the above code is the line
<item name="android:background">@android:drawable/btn_default</item>
This means that there is a drawable called btn_default set as button background.
Now we need to find a file named btn_default.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.
After a little bit searching you will find the file android-sdk\platforms\android-15\data\res\drawable\btn_default.xml
It will contain something like below :
<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" />
So this is a selector drawable. This selector chooses different backgrounds, based on the buttons state. For example a pressed button will have a different background than a non-pressed button.
So we need to look at the default (non-pressed) state of the Button.
<item android:state_enabled="true" android:drawable="@drawable/btn_default_normal" />
So the following drawable is being applied here :
btn_default_normal
We now need to find a file named btn_default_normal.* in one of the drawable folders under android-sdk\platforms\android-15\data\res.
This can be again either an image or a xml file like btn_default_normal.xml.
Now You will find multiple files called 'btn_default_normal.9.png' in different drawable folders for different resolutions.
So now you know that there is no color with a specific hex code involved in this. Its a 9 patch image (btn_default_normal.9.png).
Hope this helps.
Upvotes: 1