Import
View-based framework
Before you can use components from the Backbase Design System SDK, make sure you've installed the package and import it at the top of your file.
import com.backbase.android.design.amount.AmountTextView
Usage
Basic usage
Create an AmountTextView to display formatted monetary amounts with automatic currency formatting.
val amountTextView = AmountTextView(context)
amountTextView.amount = BigDecimal("1234.56")
amountTextView.currencyCode = "USD"
XML usage
Use AmountTextView in XML layouts with custom attributes for easy configuration.
<com.backbase.android.design.amount.AmountTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:amount="1234.56"
app:currencyCode="EUR"
app:fractionDigits="2"
app:enableIsoFormat="false" />
Configuration
|
Parameter |
Type |
Default |
|---|---|---|
|
amount |
BigDecimal |
BigDecimal.ZERO |
|
currencyCode |
String? |
null |
|
customFormatter |
AmountFormat.CustomAmountFormatter? |
null |
|
enableAbbreviation |
Boolean |
false |
|
enableCustomFractions |
Boolean |
false |
|
enableIsoFormat |
Boolean |
false |
|
enablePositiveSign |
Boolean |
false |
|
enableSignHighlight |
Boolean |
false |
|
fractionDigits |
Int |
2 |
|
highlightNegativeColor |
Int |
0 |
|
highlightPositiveColor |
Int |
0 |
|
highlightThreshold |
BigDecimal |
BigDecimal.ZERO |
|
locale |
Locale |
Locale.getDefault() |
|
maxFractionDigits |
Int |
fractionDigits |
|
minFractionDigits |
Int |
fractionDigits |
|
roundingMode |
RoundingMode |
RoundngMode.DOWN |
amount
The amount parameter sets the BigDecimal value to be formatted and displayed. This is the primary monetary value that will be processed according to the formatting configuration.
amountTextView.amount = BigDecimal("1234.56")
currencyCode
The currencyCode parameter sets the three-letter ISO 4217 currency code for formatting. When set, the amount will be displayed with the appropriate currency symbol and formatting rules.
amountTextView.currencyCode = "EUR"
customFormatter
The customFormatter parameter allows you to provide a custom implementation of AmountFormat.CustomAmountFormatter for specialized formatting needs.
amountTextView.customFormatter = object : AmountFormat.CustomAmountFormatter {
override fun format(currencyCode: String?, amount: BigDecimal): String {
return "Custom: $amount"
}
}
enableAbbreviation
The enableAbbreviation parameter controls whether large amounts should be displayed with abbreviation suffixes like "1.2k" or "1.5M".
amountTextView.enableAbbreviation = true
enableCustomFractions
The enableCustomFractions parameter determines whether to use custom fraction digits or the currency's default fraction digits.
amountTextView.enableCustomFractions = true
enableIsoFormat
The enableIsoFormat parameter forces the format to follow ISO standard formatting (e.g., "EUR 1234,56").
amountTextView.enableIsoFormat = true
enablePositiveSign
The enablePositiveSign parameter controls whether positive amounts should display a "+" sign prefix.
amountTextView.enablePositiveSign = true
enableSignHighlight
The enableSignHighlight parameter enables color highlighting based on the amount's sign relative to the highlight threshold.
amountTextView.enableSignHighlight = true
fractionDigits
The fractionDigits parameter sets the number of decimal places to display. This value is inherited by minFractionDigits and maxFractionDigits unless they are explicitly set.
amountTextView.fractionDigits = 3
highlightNegativeColor
The highlightNegativeColor parameter sets the color used when the amount is below the highlight threshold and sign highlighting is enabled.
amountTextView.highlightNegativeColor = ContextCompat.getColor(context, R.color.red)
highlightPositiveColor
The highlightPositiveColor parameter sets the color used when the amount meets or exceeds the highlight threshold and sign highlighting is enabled.
amountTextView.highlightPositiveColor = ContextCompat.getColor(context, R.color.green)
highlightThreshold
The highlightThreshold parameter sets the BigDecimal value that determines when to use positive or negative highlight colors.
amountTextView.highlightThreshold = BigDecimal("100.00")
locale
The locale parameter sets the Locale used for number formatting and display rules.
amountTextView.locale = Locale.GERMANY
maxFractionDigits
The maxFractionDigits parameter sets the maximum number of decimal places to display.
amountTextView.maxFractionDigits = 4
minFractionDigits
The minFractionDigits parameter sets the minimum number of decimal places to display.
amountTextView.minFractionDigits = 1
roundingMode
The roundingMode parameter sets how the amount should be rounded when displaying fewer decimal places than the original value.
amountTextView.roundingMode = RoundingMode.HALF_UP
Styling
Highlight colors
The AmountTextView supports automatic color highlighting based on the amount's value relative to a threshold:
- Values below highlightThreshold use highlightNegativeColor
- Values at or above highlightThreshold use highlightPositiveColor
amountTextView.enableSignHighlight = true
amountTextView.highlightThreshold = BigDecimal.ZERO
amountTextView.highlightPositiveColor = ContextCompat.getColor(context, R.color.success)
amountTextView.highlightNegativeColor = ContextCompat.getColor(context, R.color.danger)
Rounding modes
The component supports all standard Java RoundingMode values:
- RoundingMode.UP - Round away from zero
- RoundingMode.DOWN - Round towards zero (default)
- RoundingMode.CEILING - Round towards positive infinity
- RoundingMode.FLOOR - Round towards negative infinity
- RoundingMode.HALF_UP - Round to nearest neighbor, ties away from zero
- RoundingMode.HALF_DOWN - Round to nearest neighbor, ties towards zero
- RoundingMode.HALF_EVEN - Round to nearest neighbor, ties to even
- RoundingMode.UNNECESSARY - Assert exact representation
Design tokens
The AmountTextView component uses design tokens for consistent styling:
- Colors: Highlight colors use semantic color tokens colorForegroundSuccess, colorForegroundDanger)
- Typography: Inherits from MaterialTextView styling
- Formatting: Respects locale-specific number formatting rules
// Default highlight colors from design tokens
amountTextView.highlightPositiveColor = DeferredColor.Attribute(R.attr.colorForegroundSuccess).resolve(context)
amountTextView.highlightNegativeColor = DeferredColor.Attribute(R.attr.colorForegroundDanger).resolve(context)