Styling android button
If you want to style android button with custom style with background, custom font different enable disable state button colors you can do that using providing custom style to your button below is the example:
inside res/value folder
1st. style for the button
<style name=“CustomButtonStyle” parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/button_background.xml</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/black</item>
<item name="android:fontFamily">@font/font_name</item>
<item name="fontFamily">@font/font_name</item>
<item name="textAllCaps">false</item>
</style>
2nd. in background we are supplying selector so we can have different enable / disable state background and text colors
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue” android:state_enabled="true"/>
<item android:drawable="@drawable/button_with_border” android:state_enabled="false"/>
</selector>
3rd. now you see in above step we are supplying drawable in place of color for disable state because in place of just different color we want border button where we have colored border around button and different background color for that we need to take advantage of shape property
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<stroke
android:width=“1dp"
android:color="@color/blue” />
</shape>
Comments
Post a Comment