|
| 1 | +## Theming |
| 2 | + |
| 3 | +- [Theming](#theming) |
| 4 | + - [Colors](#colors) |
| 5 | + - [Animation](#animation) |
| 6 | + - [Default themes](#default-themes) |
| 7 | + - [Light theme](#light-theme) |
| 8 | + - [Dark theme](#dark-theme) |
| 9 | + |
| 10 | +The appearance of the payment dialog can be customized to match the look and feel of your app. This can be done for both the light and dark theme individually. |
| 11 | + |
| 12 | +Colors can be modified by passing a JSON object to the `PostFinanceCheckoutSdk` instance. You can either completely override the theme or only change certain colors. |
| 13 | + |
| 14 | +- `PostFinanceCheckoutSdk.instance?.setLightTheme(JSONObject)` allows to modify the payment dialog's light theme. |
| 15 | +- `PostFinanceCheckoutSdk.instance?.setDarkTheme(JSONObject)` allows to modify the payment dialog's dark theme. |
| 16 | +- `PostFinanceCheckoutSdk.instance?.setCustomTheme(JSONObject, ThemeEnum)` allows to enforce a specific theme (dark, light or your own). |
| 17 | + |
| 18 | +```kotlin |
| 19 | +// ... |
| 20 | +import ch.postfinance.enums.ThemeEnum |
| 21 | + |
| 22 | +class MainActivity : AppCompatActivity() { |
| 23 | + // ... |
| 24 | + |
| 25 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 26 | + super.onCreate(savedInstanceState) |
| 27 | + setContentView(R.layout.activity_main) |
| 28 | + |
| 29 | + PostFinanceCheckoutSdk.instance?.setDarkTheme(getCustomTheme()) |
| 30 | + PostFinanceCheckoutSdk.instance?.setLightTheme(getCustomTheme()) |
| 31 | + } |
| 32 | + |
| 33 | + fun getCustomTheme(): JSONObject { |
| 34 | + val customTheme = JSONObject() |
| 35 | + customTheme.put("colorBackground", "#ABA2A2") |
| 36 | + customTheme.put("colorText", "#2F4858") |
| 37 | + customTheme.put("colorHeadingText", "#4F5769") |
| 38 | + customTheme.put("colorError", "#998D91") |
| 39 | + return customTheme |
| 40 | + } |
| 41 | + |
| 42 | + // ... |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +This will override the colors `colorBackground`, `colorText`, `colorHeadingText` and `colorError` for both the dark and light theme. |
| 47 | + |
| 48 | +The `setCustomTheme` function allows to define the theme to be used by the payment dialog and prevent it from switching themes based on the user's settings. This way e.g. high- and low-contrast themes can be added. The logic for switching between these themes is up to you though. |
| 49 | + |
| 50 | +```kotlin |
| 51 | +// ... |
| 52 | +import ch.postfinance.enums.ThemeEnum |
| 53 | + |
| 54 | +class MainActivity : AppCompatActivity() { |
| 55 | + // ... |
| 56 | + |
| 57 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 58 | + super.onCreate(savedInstanceState) |
| 59 | + setContentView(R.layout.activity_main) |
| 60 | + |
| 61 | + PostFinanceCheckoutSdk.instance?.setCustomTheme(getCustomTheme(), ThemeEnum.DARK) |
| 62 | + } |
| 63 | + |
| 64 | + fun getCustomTheme(): JSONObject { |
| 65 | + val customTheme = JSONObject() |
| 66 | + customTheme.put("colorBackground", "#0800FC") |
| 67 | + customTheme.put("colorText", "#EA00B6") |
| 68 | + customTheme.put("colorHeadingText", "#FF0071") |
| 69 | + customTheme.put("colorError", "#FF693E") |
| 70 | + return customTheme |
| 71 | + } |
| 72 | + |
| 73 | + //... |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +You can also use `setCustomTheme` to force the usage of the light or dark theme. |
| 78 | + |
| 79 | +```kotlin |
| 80 | + //... |
| 81 | +PostFinanceCheckoutSdk.instance?.setCustomTheme(null, ThemeEnum.DARK) |
| 82 | +``` |
| 83 | + |
| 84 | +### Colors |
| 85 | + |
| 86 | +   |
| 87 | + |
| 88 | +### Animation |
| 89 | + |
| 90 | +Use `setAnimation` method to change the screen change animation. Currently avaliable options are: `AnimationEnum.SLIDE` and `AnimationEnum.BUBBLE`. Default value is `AnimationEnum.SLIDE`. `PostFinanceCheckoutSdk.instance?.setAnimation(AnimationEnum.BUBBLE)` allows to modify the payment dialog's dark theme.   |
| 91 | + |
| 92 | +### Default themes |
| 93 | + |
| 94 | +#### Light theme |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "colorPrimary": "#3b82f6", |
| 99 | + "colorBackground": "#ffffff", |
| 100 | + "colorText": "#374151", |
| 101 | + "colorSecondaryText": "#6b7280", |
| 102 | + "colorHeadingText": "#111827", |
| 103 | + "colorError": "#ef4444", |
| 104 | + "toast": { |
| 105 | + "border": "#F14D00", |
| 106 | + "background": "#FFF6F6", |
| 107 | + "messageText": "#ef4444" |
| 108 | + }, |
| 109 | + "component": { |
| 110 | + "colorBackground": "#ffffff", |
| 111 | + "colorBorder": "#d1d5db", |
| 112 | + "colorText": "#374151", |
| 113 | + "colorPlaceholderText": "#4b5563", |
| 114 | + "colorFocus": "#3b82f6", |
| 115 | + "colorSelectedText": "#1e3a8a", |
| 116 | + "colorSelectedBackground": "#eff6ff", |
| 117 | + "colorSelectedBorder": "#bfdbfe", |
| 118 | + "colorDisabledBackground": "#80808019" |
| 119 | + }, |
| 120 | + "buttonPrimary": { |
| 121 | + "colorBackground": "#2563eb", |
| 122 | + "colorText": "#ffffff", |
| 123 | + "colorHover": "#1d4ed8" |
| 124 | + }, |
| 125 | + "buttonSecondary": { |
| 126 | + "colorBackground": "#bfdbfe", |
| 127 | + "colorText": "#1d4ed8", |
| 128 | + "colorHover": "#bfdbfe" |
| 129 | + }, |
| 130 | + "buttonText": { |
| 131 | + "colorText": "#6b7280", |
| 132 | + "colorHover": "#374151" |
| 133 | + }, |
| 134 | + "buttonIcon": { |
| 135 | + "colorText": "#9ca3af", |
| 136 | + "colorHover": "#6b7280" |
| 137 | + } |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +#### Dark theme |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "colorPrimary": "#3b82f6", |
| 146 | + "colorBackground": "#1f2937", |
| 147 | + "colorText": "#e5e7eb", |
| 148 | + "colorSecondaryText": "#9ca3af", |
| 149 | + "colorHeadingText": "#f9fafb", |
| 150 | + "colorError": "#ef4444", |
| 151 | + "toast": { |
| 152 | + "border": "#F14D00", |
| 153 | + "background": "#222222", |
| 154 | + "messageText": "#ef4444" |
| 155 | + }, |
| 156 | + "component": { |
| 157 | + "colorBackground": "#374151", |
| 158 | + "colorBorder": "#6b7280", |
| 159 | + "colorText": "#f3f4f6", |
| 160 | + "colorPlaceholderText": "#9ca3af", |
| 161 | + "colorFocus": "#3b82f6", |
| 162 | + "colorSelectedText": "#f3f4f6", |
| 163 | + "colorSelectedBackground": "#4b5563", |
| 164 | + "colorSelectedBorder": "#9ca3af", |
| 165 | + "colorDisabledBackground": "#9ca3af" |
| 166 | + }, |
| 167 | + "buttonPrimary": { |
| 168 | + "colorBackground": "#2563eb", |
| 169 | + "colorText": "#ffffff", |
| 170 | + "colorHover": "#1d4ed8" |
| 171 | + }, |
| 172 | + "buttonSecondary": { |
| 173 | + "colorBackground": "#6b7280", |
| 174 | + "colorText": "#f3f4f6", |
| 175 | + "colorHover": "#4b5563" |
| 176 | + }, |
| 177 | + "buttonText": { |
| 178 | + "colorText": "#9ca3af", |
| 179 | + "colorHover": "#d1d5db" |
| 180 | + }, |
| 181 | + "buttonIcon": { |
| 182 | + "colorText": "#d1d5db", |
| 183 | + "colorHover": "#f3f4f6" |
| 184 | + } |
| 185 | +} |
| 186 | +``` |
0 commit comments