Coloring Social Networks Buttons

- Create three “shape drawable” XML files under res/drawable-hpdi
- button_fb_gb.xml (for Facebook)
- button_gplus_gb.xml (for Google+)
- button_twitter_gb.xml (for Twitter)
- Each XML file is defining the geometric shape, color and gradient for each button in two different states “press and normal states”
- All XML files have the below structure. The only difference is the color hex number for each button.
- res/drawable-hpdi/button_fb_gb.xml Color1=#449def | Color2=#2f6699
- res/drawable-hpdi/button_gplus_gb.xml Color1=#ef4444 | Color2=#992f2f
- res/drawable-hpdi/button_twitter_gb.xml Color1=#74b7e0 | Color2=#4b9ed1
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#[Color1]" />
<stroke
android:width="1dp"
android:color="#[Color2]" />
<corners
android:radius="1dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#[Color1]"
android:endColor="#[Color2]"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#[Color2]" />
<corners
android:radius="1dp" />
</shape>
</item>
</selector>
Set the background of each button to the corresponding XML shape file.
<Button
.......
android:background="@drawable/button_fb_bg"
android:text="Sign in with Facebook"
/>