如何在Android上设置属性android:layoutDirection
的通用值?因此,我将能够针对不同的语言环境使用不同的值。
我尝试了以下操作(在最后两行中使用strings.xml
):
android:layoutDirection="@string/autortl"
<string name="autortl" tools:ignore="MissingTranslation">ltr</string> // main locale
<string name="autortl">rtl</string> // for RTL locales
但这不适用于运行时错误:android.view.InflateException: Binary XML file line #381: Binary XML file line #381: Error inflating class <unknown>
答案 0 :(得分:0)
以下代码可以正常工作(在最后两行中使用integers.xml
):
android:layoutDirection="@integer/autortl"
<integer name="autortl">0</integer> // main locale
<integer name="autortl">1</integer> // for RTL locales
答案 1 :(得分:0)
更好的答案-只需使用以下代码即可
android:layoutDirection="locale"