How can I set universal value of the attribute android:layoutDirection on Android?
How can I set universal value of the attribute android:layoutDirection on Android?
How can I set universal value of the attribute android:layoutDirection
on Android? So, I'd be able to use different values for different locales.
android:layoutDirection
I tried the following (using strings.xml
for the last two lines):
strings.xml
android:layoutDirection="@string/autortl"
<string name="autortl" tools:ignore="MissingTranslation">ltr</string> // main locale
<string name="autortl">rtl</string> // for RTL locales
But it doesn't work with the run-time error: android.view.InflateException: Binary XML file line #381: Binary XML file line #381: Error inflating class <unknown>
android.view.InflateException: Binary XML file line #381: Binary XML file line #381: Error inflating class <unknown>
error: invalid dimen.
2 Answers
2
The following code works fine (use integers.xml
for the last two lines):
integers.xml
android:layoutDirection="@integer/autortl"
<integer name="autortl">0</integer> // main locale
<integer name="autortl">1</integer> // for RTL locales
Better answer - just use the following code instead:
android:layoutDirection="locale"
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
Dimens also don't work with the error:
error: invalid dimen.
– Dmitry
Sep 16 '18 at 2:50