AppCompatTextView, giving you access to all standard TextView functionality plus additional customization options. You can customize buttons via XML attributes or programmatically.
XML attributes
Customize your buttons directly in your layout XML using these custom attributes:Default background color of the button
Background color when the button is pressed or selected
Default outline/border color
Outline color when the button is pressed or selected
Default text color
Text color when the button is pressed or selected
Thickness of the outline border in pixels
Radius of rounded corners in pixels
Example
Here’s a complete example showing all customization attributes:Programmatic customization
You can also customize buttons programmatically using Java/Kotlin code.Set press status
Manually set the button’s appearance to selected or default state:Set to
true for selected state, false for default stateSet all colors at once
Use thesetColor() method to update all button colors programmatically:
Text color in default state
Text color when pressed
Background color in default state
Background color when pressed
Outline color in default state
Outline color when pressed
Color formats
In XML
Use standard Android color formats:In Java/Kotlin
Use Android’sColor class:
Best practices
Use consistent corner radius
Use consistent corner radius
Keep the same
btn_cornerRadius value across all buttons in your app for visual consistency. Common values are 20dp for fully rounded buttons or 8dp for slightly rounded corners.Ensure sufficient contrast
Ensure sufficient contrast
Make sure there’s enough contrast between text color and background color for readability, especially in the pressed state.
Define pressed states
Define pressed states
Always define
btn_buttonSelectColor, btn_strokeSelectColor, and btn_textSelectColor to provide clear visual feedback when users interact with your buttons.Use color resources
Use color resources
Define colors in
colors.xml and reference them with @color/name for easier maintenance and theming support.Next steps
Button styles
Explore pre-configured button styles
Drawables
Add icons to your buttons