开发者

How get the current language setting on Android

开发者 https://www.devze.com 2023-03-06 08:48 出处:网络
I want to change the view of my TimePicker to 24h, if开发者_运维问答 a user of Germany is watching it.

I want to change the view of my TimePicker to 24h, if开发者_运维问答 a user of Germany is watching it.

So I want to have a code like this:

if(language-setting = Germany)
    tp.setIs24HourView(true);
else
    tp.setIs24HourView(false);

I think it should somehow work with "locale", but I can not figure it out.


Try this one

String language=Locale.getDefault().getLanguage();
    Log.d("lang", "langg"+language);
    if(language.equals("en")){
        Log.d("lang_english", "langg"+language);
        //send_msg_text.
    }
    if(language.equals("ar")){
        Log.d("lang_arabic", "langg"+language);
    }


You should be respecting the user setting, which you can get from DateFormat.is24HourFormat().


Use:

context.getResources().getConfiguration().locale;


This should give you the current default

Locale.getDefault();

Based on this you can compare.

0

精彩评论

暂无评论...
验证码 换一张
取 消