Custom Theme APIs¶
Custom Theme supports the capability to change the color theme dynamically during runtime for those activities that use it.
Overview¶
A custom theme is used in activities like any other theme. This theme (by default) reflects the same color theme as the Fiori.Horizon
theme. In addition, the basic behavior can be overridden by the provided APIs.
Custom Theme API¶
Custom Theme APIs are a set of APIs used to modify the color value at runtime. The new color mapping is provided in JSON
format. The mapping can be in a file specified by file name, it can be referred to by an inputStream
instance, or it can be specified using a character sequence.
JSON
Description of Custom Theme Mapping¶
The contents of the color mapping JSON
file should look like the following:
{
"mapping" : [
{"color":"s2", "value": "#FF00FF00"},
{"color":"s2_dark", "value": "#FF00FF01"}
]
}
````
A complete list of the mappings can be found at [UI Colors](https://experience.sap.com/fiori-design-android/colors/#ui-colors).
The mapping is an array of key-value pairs. Each key-value pair consists of the name of the color along with its new value. For example, in the preceding text, `s2` (the surface color 2) is mapped to an RGB value, `#FF00FF00`, and `s2_dark` for the dark theme is mapped to `#FF00FF01`.
#### `CustomColorMapper`
Custom Color Mapper provides an interface to use the color mapping provided as `JSON` data in order to update the Android resources data. An instance of `CustomColorMapper` is created as follows:
`CustomColorMapper mapper = new CustomColorMapper(context)`
````Java
Context appContext = InstrumentationRegistry.
getInstrumentation().getTargetContext();
CustomColorMapper colorMapper = new CustomColorMapper(appContext);
updateColor(InputStream inputStream)
This function reads the input stream for valid JSON
data specifying color mapping and updates the Android resources data.
This updates the Android resources data dynamically, reading the mapping data from the JSON
file in the assets folder.
The contents of the file should look similar to the following:
{
"mapping" : [
{"color":"morning_s2", "value": "#FF00FF00"}
]
}
updateColors(String fileName)
This function reads the input file given by the argument for valid JSON
data specifying color mapping and updates the Android resources data.
This updates the Android resources dynamically, reading the mapping data from the JSON
file in the assets folder.
The contents of the file should look similar to the following: { "mapping" : [ {"color":"morning_s2", "value": "#FF00FF00"} ] }
updateColors(CharSequence jsonCharSequence)
This function takes input in the form of character sequences in valid JSON
format to specify the new color mapping.
This updates the Android resources dynamically, reading the mapping data from the JSON
file in the assets folder.
The contents of the file should look similar to the following: { "mapping" : [ {"color":"morning_s2", "value": "#FF00FF00"} ] }