Skip to main content
CustomButton provides several public methods to control its appearance and behavior at runtime.

setPressStatus

Set the button’s appearance to selected or unselected state programmatically.
public void setPressStatus(boolean isPress)
isPress
boolean
required
true to show the selected/pressed state, false to show the normal state
Example:
CustomButton button = findViewById(R.id.my_button);
button.setPressStatus(true); // Show selected state

setDrawableLeft

Add a drawable icon to the left side of the button text.

Basic usage

public void setDrawableLeft(int imgResId)
imgResId
int
required
The drawable resource ID
The drawable will be sized to match the line height of the text.

Advanced usage

public void setDrawableLeft(int imgResId, int width, int height)
imgResId
int
required
The drawable resource ID
width
int
required
The drawable width in pixels
height
int
required
The drawable height in pixels
Example:
CustomButton button = findViewById(R.id.my_button);
button.setDrawableLeft(R.drawable.ic_star); // Auto-sized
button.setDrawableLeft(R.drawable.ic_star, 48, 48); // Custom size

setDrawableRight

Add a drawable icon to the right side of the button text.

Basic usage

public void setDrawableRight(int imgResId)
imgResId
int
required
The drawable resource ID
The drawable will be sized to match the line height of the text.

Advanced usage

public void setDrawableRight(int imgResId, int width, int height)
imgResId
int
required
The drawable resource ID
width
int
required
The drawable width in pixels
height
int
required
The drawable height in pixels
Example:
CustomButton button = findViewById(R.id.my_button);
button.setDrawableRight(R.drawable.ic_arrow); // Auto-sized
button.setDrawableRight(R.drawable.ic_arrow, 32, 32); // Custom size

setColor

Set all color properties of the button at once.
public void setColor(
    int textnormal,
    int textselected,
    int buttonnormal,
    int buttonselected,
    int strokenormal,
    int strokeselected
)
textnormal
int
required
Text color in normal state
textselected
int
required
Text color when pressed
buttonnormal
int
required
Background color in normal state
buttonselected
int
required
Background color when pressed
strokenormal
int
required
Outline color in normal state
strokeselected
int
required
Outline color when pressed
Example:
CustomButton button = findViewById(R.id.my_button);
button.setColor(
    Color.WHITE,           // text normal
    Color.LTGRAY,          // text selected
    Color.parseColor("#FF6200EE"), // button normal
    Color.parseColor("#FF3700B3"), // button selected
    Color.parseColor("#FF3700B3"), // stroke normal
    Color.parseColor("#FF6200EE")  // stroke selected
);
This method provides a convenient way to theme the button programmatically without setting each color attribute individually.

Build docs developers (and LLMs) love