Whenever I open the odk form on my phone, all the headings (text) appear on the far-left side of the phone while I want the text to appear in the centre of the phone. Is there a way to align text at the middle of the ODK?
U̶n̶f̶o̶r̶t̶u̶n̶a̶t̶e̶l̶y̶,̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶t̶h̶i̶n̶k̶ ̶t̶h̶a̶t̶ ̶i̶s̶ ̶p̶o̶s̶s̶i̶b̶l̶e̶.̶ [EDIT: see @Grzesiek2010 's answer below]
The available styling options are described in https://docs.getodk.org/form-styling/ .
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
Thanks for sharing a solution, but it seems that it doesnt work with notes? is there a specific setting to style notes?
Hi @NWS_MEAL_Manager
We're glad you're here. When you get a chance, please introduce yourself on this forum thread . I'd also encourage you to add a real picture as your avatar because it helps build community!
It should work with notes as well:
what version of ODK Collect are you using? Could you attach your form?
hi @Grzesiek2010 , thank you for your answers! sadly I tried for note and couldn't manage to do it:
this is my test form:
a7dJK3W4kzxFKJPrmF8PqD.xlsx (8.8 KB)
this is the result
my version:
906addf66af230735e501ad73a1269012fdd7a5a (v2023.3.1)
I read a post that this might be supported for odk, but not for enketo, is this right?
Hi @rmirabal
ODK Collect and Enketo are two different tools (the same purpose but completely separate). There are lots of things that might work well in Collect but not Enketo and the other way around. It seems like it's only about centering? Or maybe I'm missing something?
thank you, I am familiarizing, yes it is about centering, only format