Skip to main content
CustomButton extends 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:
btn_buttonColor
color
Default background color of the button
btn_buttonSelectColor
color
Background color when the button is pressed or selected
btn_strokeColor
color
Default outline/border color
btn_strokeSelectColor
color
Outline color when the button is pressed or selected
btn_textColor
color
Default text color
btn_textSelectColor
color
Text color when the button is pressed or selected
btn_strokeWidth
dimension
Thickness of the outline border in pixels
btn_cornerRadius
dimension
Radius of rounded corners in pixels

Example

Here’s a complete example showing all customization attributes:
<stream.custombutton.CustomButton
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Custom Button"
    android:textSize="18sp"
    android:singleLine="true"
    android:ellipsize="none"
    app:btn_cornerRadius="20dp"
    app:btn_strokeWidth="1dp"
    app:btn_strokeColor="#008af9"
    app:btn_buttonColor="#00FFFFFF"
    app:btn_buttonSelectColor="#008af9"
    app:btn_textColor="#008af9"
    app:btn_textSelectColor="#FFFFFF"/>
Use transparent colors (alpha channel #00) for btn_buttonColor to create outline-only buttons.

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:
CustomButton button = findViewById(R.id.btn);
button.setPressStatus(true);  // Show selected state
button.setPressStatus(false); // Show default state
isPress
boolean
required
Set to true for selected state, false for default state

Set all colors at once

Use the setColor() method to update all button colors programmatically:
CustomButton button = findViewById(R.id.btn);
button.setColor(
    Color.parseColor("#008af9"),  // text color
    Color.WHITE,                   // text color when pressed
    Color.TRANSPARENT,             // background color
    Color.parseColor("#008af9"),  // background color when pressed
    Color.parseColor("#008af9"),  // outline color
    Color.parseColor("#0070cc")   // outline color when pressed
);
textnormal
int
required
Text color in default state
textselected
int
required
Text color when pressed
buttonnormal
int
required
Background color in default state
buttonselected
int
required
Background color when pressed
strokenormal
int
required
Outline color in default state
strokeselected
int
required
Outline color when pressed

Color formats

In XML

Use standard Android color formats:
<!-- Hex color -->
app:btn_buttonColor="#008af9"

<!-- Hex color with alpha -->
app:btn_buttonColor="#80008af9"

<!-- Color resource -->
app:btn_buttonColor="@color/primary"

<!-- Transparent -->
app:btn_buttonColor="@color/transparent"
app:btn_buttonColor="#00FFFFFF"

In Java/Kotlin

Use Android’s Color class:
// Parse hex string
int color = Color.parseColor("#008af9");

// Use predefined colors
int white = Color.WHITE;
int transparent = Color.TRANSPARENT;

// Create from RGB values
int color = Color.rgb(0, 138, 249);

// Load from resources
int color = ContextCompat.getColor(context, R.color.primary);

Best practices

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.
Make sure there’s enough contrast between text color and background color for readability, especially in the pressed state.
Always define btn_buttonSelectColor, btn_strokeSelectColor, and btn_textSelectColor to provide clear visual feedback when users interact with your buttons.
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

Build docs developers (and LLMs) love