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>






Dimens also don't work with the error: error: invalid dimen.

– Dmitry
Sep 16 '18 at 2:50


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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)