It is possible. Here is a sample form:
centerText.xlsx (6.1 KB)
However there are some limitations:
we don't support styling groups: https://github.com/getodk/collect/issues/3433
the centered text will be centered horizontally but not vertically (it's more a bug in one of Android's classes but we can handle it so I'll try to fix the bug soon)
Edit: I created a pull request to fix that extra space which is added when centering is used:
getodk:master
← grzesiek2010:COLLECT-4370
opened 01:06PM - 29 Jan 21 UTC
Closes #4370
| Before | After |
| ------------- | ------------- |
|  |  |
#### What has been done to verify that this works as intended?
I added one test and also verified the fix manually.
#### Why is this the best possible solution? Were any other approaches considered?
The problem was that in some case [Html.fromHtml()](https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)) might return values with new lines at the end for example. See:
https://stackoverflow.com/questions/9589381/remove-extra-line-breaks-after-html-fromhtml/9974562
#### How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
It's a safe fix and we can just test the scenario described in the issue.
#### Do we need any specific form for testing your changes? If so, please attach one.
The form attached to the issue.
#### Does this change require updates to documentation? If so, please file an issue [here]( https://github.com/getodk/docs/issues/new) and include the link below.
Yes I think we should add info about centering in https://docs.getodk.org/form-styling/ so that it's clear for our users.
https://github.com/getodk/docs/issues/1315
#### Before submitting this PR, please make sure you have:
- [x] run `./gradlew checkAll` and confirmed all checks still pass OR confirm CircleCI build passes and run `./gradlew connectedDebugAndroidTest` locally.
- [x] verified that any code or assets from external sources are properly credited in comments and/or in the [about file](https://github.com/getodk/collect/blob/master/collect_app/src/main/assets/open_source_licenses.html).
- [x] verified that any new UI elements use theme colors. [UI Components Style guidelines](https://github.com/getodk/collect/blob/master/CONTRIBUTING.md#ui-components-style-guidelines)
2 Likes