Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

android determine if device is in right to left language/layout

Is there a way to determine if the device is in a right to left language (something like Arabic) as opposed to something that's left to right (English)?

Something compatible with older API levels (down to 10) is necessary

SOLUTION

i ended up using the xml method in the accepted answer. Farther down the line, i also added the code indicated here for instances where I didn't have access to getResources()

Identifying RTL language in Android

more info

This question still gets a lot of traffic; something else I wanted to point out: When I originally asked this I think it was partially to help address showing different pointing chevrons in RTL vs LTR -- another slick way of accomplishing this is by placing drawable resources in the standard and ldrtl directories -- means no code required to determine which one to show!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could create a values-ldrtl folder with a xml file called isrighttoleft.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_right_to_left">true</bool>
</resources>

and in your values folder the same file with:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_right_to_left">false</bool>
</resources>

And finally in Code:

boolean isRightToLeft = getResources().getBoolean(R.bool.is_right_to_left);

The values-ldrtl will only be used on a device where the specific settings (e. g. Language) are right-to-left-read languages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...