Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:52:10+00:00 2026-06-16T20:52:10+00:00

How can I change content language in my WebView. My exampe (below) works good,

  • 0

How can I change content language in my WebView. My exampe (below) works good, but it changing only when I change phone language. The problem is when I change language inside of my App – menu, text, names etc. changing except content in webview.

public class WebViewActivity extends Activity {

WebView mWebView;

        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.web_view_activity); // ID Activity


    mWebView = (WebView) findViewById(R.id.webview); // ID webview
    mWebView.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
    mWebView.getSettings().setAllowFileAccess(true); // File access

            String lang = Locale.getDefault().getLanguage();
    String filename = "www/index.html";
    if (lang.equals("en")) {
      filename = "www/index.en.html";
    }
    mWebView.loadUrl("file:///android_asset/" + filename);

LANGUAGE CLASS

import java.util.Locale;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.ListPreference;
import android.preference.PreferenceManager;
import android.preference.PreferenceActivity;

import com.training.MainActivity;
import com.training.programs.R;


public class LanguageLocale extends PreferenceActivity implements
        Preference.OnPreferenceChangeListener {

    PreferenceManager manager;
    ListPreference listPreference;
    SharedPreferences sharedPreference;
    Locale RUSSIAN= new Locale("ru", "ua");
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.language_option_preference);
        sharedPreference = PreferenceManager.getDefaultSharedPreferences(this);

        manager = getPreferenceManager();
        listPreference = (ListPreference) manager.findPreference("language_setting");

        listPreference.setOnPreferenceChangeListener(this);
    }



    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {

        Resources resource = getResources();
        Configuration config = resource.getConfiguration();

        int pos = Integer.parseInt((String) newValue);
        if (pos == 1) {
            sharedPreference.edit().putString("language", "en").commit();
            config.locale = Locale.ENGLISH;
            listPreference.setValue("1");

        } else if (pos == 2) {
            sharedPreference.edit().putString("language", "ru").commit();

            config.locale = RUSSIAN;
            listPreference.setValue("2");
        } else {
            sharedPreference.edit().putString("language", "auto").commit();
            config.locale = Locale.getDefault();
            listPreference.setValue("0");
        }

        getBaseContext().getResources().updateConfiguration(config, null);

        Intent intent = new Intent();
        intent.setClass(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        this.startActivity(intent);
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:52:11+00:00Added an answer on June 16, 2026 at 8:52 pm

    You probably keep your app lang some where, so you should add a method to get the right lang :

    private String mLang;
    public String getMyAppLang(){        
        if (mLang==null)
            mLang = Locale.getDefault().getLanguage();
        return mLang;
    }
     public void setMyAppLang(String lang){
        mLang = lang;
     }
    

    When the user modify the lang inside your app, you call setMyAppLang(lang);
    And in your activity code:

    String lang = getMyAppLang();
    

    Instead of:

    String lang = Locale.getDefault().getLanguage();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I change the content of my facebook share option? my web app
Pagination is hard when your content rankings can change quickly, and even harder when
using RewriteCond or similar mechanism on apache, can i change how fast content is
How i can change the color with gradient??? I have this now,but is different
I have a business application (created from template) and I can change language dynamically
I usually get the country from the device's language. It works but now I
I'm trying to use Knockoutjs to dynamically change the language/content of the labels on
How can I make my <div> elements grow (and the content changes text size
I can change SQL at runtime. Can I do the same with LINQ ?
I can change the irb prompt mode with irb --prompt prompt-mode I can see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.