Android获取语言及地区总结

##Android获取语言及地区总结

Android中获取的地区是语言地区,它是随着系统语言的改变而改变的

获取语言和地区分为两种:
获取系统语言和获取当前资源语言

###获取系统语言:


//Android 7.0以前
Locale locale = Locale.getDefault();
Log.d("------------"+locale.getLanguage() + "-" + locale.getCountry());


//Android 7.0以后
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            LocaleListCompat listCompat=ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
            for (int i = 0; i < listCompat.size(); i++) {
                AppLog.d(i + " ------1> " + listCompat.get(i).getLanguage() + "-" + listCompat.get(i).getCountry());
            }
        }

###获取当前资源配置的语言:

Locale locale = getResources().getConfiguration().locale;
Log.d("------------"+locale.getLanguage() + “-” + locale.getCountry());

但是,在 Android 7.0 上:getResources().getConfiguration().locale 被标记为 deprecated 了,所以初步适配后是:

Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    locale = getResources().getConfiguration().getLocales().get(0);
} else {
    locale = getResources().getConfiguration().locale;
}

//或者仅仅使用 locale = Locale.getDefault(); 不需要考虑接口 deprecated(弃用)问题
String lang = locale.getLanguage() + “-” + locale.getCountry();

###参考
https://likfe.com/2017/05/10/android-sys-language/
https://www.jishux.com/p/3e7b32b1d4d8693a

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
声明:这些内容是逐步总结过来的,所以可能有当时的理解不正确,只希望大家能做个参考: 内容如下: 目录 一句话总结汇总: Copy project into workspace 和add project into work set 的含义 数字签名总结 JNI 基础及注意: Ndk的使用方法: Ant 与 android update project 命令行只有在非根盘符上才能运行 android Launcher Android 运行环境搭建 Android:name什么时候加”.” Activity class {package/class} does not exist 问题的解决 Activity 中两次调用OnCreate的原因 ByteBuffer 和 FloatBuffer 的直接分配和非直接分配 Application的使用小总结 “call to OpenGL ES API with no current context (logged once per thread” 问题的解决 2013年9月7日19:15:33:我的平板分辨率很高可是运行public void onSurfaceChanged(GL10 gl, int width, int height)函数时,分辨率只有 455*320,这是为什么? 关于android添加第三方字体的方法 android-apt-compiler: [t1] res\layout\LinearLayout.xml: Invalid file name: must contain only [a-z0-9_.] Buttons in button bars should be borderless android 支持的距离单位 使用adb shell命令进入手机后使用ls命令提示: opendir failed permission denied 使用adb pull 命令提示permission denied Button 中的setLayoutParams使用注意: layout文件夹和raw文件下面的文件读取 Matrix方法中的set方法和post方法 android 中调用drawBitmap时理解dip(屏幕密度)和px(像素)的区别 SQLiteDatabase 的setTransactionSuccessful作用 终于弄明白 paddingleft margineleft layout_gravity 和gravity之间的区别 自定义控件时要注意的问题。 obtainMessage 的作用: FrameLayout 需要注意的地方: EditText 禁止弹出按键盘: 获取控件屏幕位置和窗口位置: 为什么MyAdapater的getView没有被调用 XmlSerializer使用总结: ListView中的Item自定义点击后的背景色的方法。 drawable各个分辨率 fragment 的几种创建方式 fragment第一次使用遇到的问题 activity变身对话框 onMeasure 中的AT_MOST EXACTLY UNSPECIFIED MotionEvent的触发记录 对于Drawable 的 getIntrinsicHeight 和getIntrinsicWidth的理解 IntentService 使用总结: 文件读写总结: AES 解密失败: XML中的include标签加入后崩溃 Button的background标签使图像拉伸的问题 SharedPreferences 的getString 的陷阱 TextView 中的EMS和Maxlength

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值