代码之家  ›  专栏  ›  技术社区  ›  Racer

手机中的语言变化并没有影响Android应用程序

  •  0
  • Racer  · 技术社区  · 7 年前
    <resources>
        <string name="otpValidationMessage">Please enter the One Time Password\n and validate your phone number</string>
    
        <string name="firstName">First Name</string>
        <string name="lastName">Last Name</string>
        <string name="mobileNumber">Mobile Number</string>
        <string name="otpPassword">One Time Password</string>
        <string name="code">Code</string>
        <string name="resendOTp">Resend OTP</string>
    

    我已经更改了手机语言,但在我的应用程序中没有看到语言的更改。我的所有文本都在字符串文件中,但应用程序中仍然没有任何更改。

    1 回复  |  直到 7 年前
        1
  •  2
  •   g7pro    7 年前

    myLocale = new Locale("ar");//"en" if you want english
    Locale.setDefault(myLocale);
    android.content.res.Configuration config = new android.content.res.Configuration();
    config.locale = myLocale;
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    your_text_view.setText(R.string.Name);
    

    在字符串中创建为res/values-ar/string。xml

    <string name="Name">Arabi</string>
    

    在字符串中创建为res/values-en/string。xml

    <string name="Name">English</string>