Solution 1 :
Going through different releated posts, I found something similar here in this post and tried something similar. Reloading the localization settings after setContentView(webview_layout)
worked. There is some bug/issue in the WebView in android OS that resets all the localization settings and put it back to default settings once the layout is loaded.
Problem :
I’m trying to localize my app in android studio. All works great unless I open this one specific activity and everything starts going crazy. My app supports English and Arabic language.
All strings are available in both resources sets(strings-en.xml and strings-ar.xml) English is the base language in app.
I have 8-10 different activities and fragments. I can open all activities and fragments and everything is localized BUT there is only one activity where everything messes up and after that activity all screens starts showing default localization(en). In this one activity I’ve a webview and some IntentExtras to deal with and read the urls and title of the activity. Even the default URL and Title that i’ve defined in the strings.xml is not localized.
Any help is appreciated.
This is a code snippet from WebviewActivity, I’m simply doing startActivity from previous and setting “target” and “url” in IntentExtras.
String title = getText(R.string.BrandName).toString();
target = getIntent().getIntExtra("target", 0);
switch (target){
case 1:
title = getText(R.string.terms).toString();
Url = getText(R.string.terms_url).toString();
break;
default:
title = getText(R.string.default).toString();
Url = getText(R.string.default_url).toString();
break;
}
getSupportActionBar().setTitle(title);
webview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns_android="http://schemas.android.com/apk/res/android"
android_layout_width="match_parent"
android_layout_height="match_parent"
android_background="@color/offwhite">
<include layout="@layout/app_bar_layout" />
<LinearLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_orientation="vertical"
android_visibility="gone"
android_layout_centerInParent="true"
android_id="@+id/noInternetLayout"
android_layout_margin="@dimen/dimen_10">
<ImageView
android_layout_width="100dp"
android_layout_height="100dp"
android_layout_gravity="center"
android_tint="@color/grey"
android_src="@drawable/ic_nonet"
android_layout_margin="@dimen/dimen_4"/>
<TextView
android_layout_width="match_parent"
android_layout_height="match_parent"
android_layout_margin="@dimen/dimen_4"
android_textAlignment="center"
android_text="@string/noInternetConnection"
android_textStyle="bold|italic" />
</LinearLayout>
<WebView
android_layout_width="match_parent"
android_layout_height="match_parent"
android_id="@+id/webView"
android_layout_below="@+id/appbar"
android_visibility="gone"/>
<ProgressBar
android_id="@+id/progressBar"
android_progressTint="@color/grey"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_centerHorizontal="true"
android_layout_centerVertical="true"
android_layout_centerInParent="true"
/>
</RelativeLayout>
Comments
Comment posted by Lena Bru
please share the code of how you display the webview
Comment posted by Joe
I was just trying different things and found out that if i put