Issue
My app default language is Spanish (es). I have introduced a webview in XML. Prior to this change, the language is Spanish. After adding the webview, it's automatically showing English. How can I fix this issue or problem?
Thanks for helping in advance. I already used below code too.
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(String.valueOf(Locale.SPANISH));
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-5dp"
tools:ignore="WebViewLayout" />
Solution
You can dynamically add web view and initialize the language again after that.
llDynemic=(LinearLayout)findViewById(R.id.test);
WebView webView = new WebView(getContext());// webview in mainactivity
webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
webView.setBackgroundColor(Color.TRANSPARENT);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;} a {color: #337ab7;}</style>" + newBody, "text/html", "UTF-8", null);
llDynemic.addView(webView);
// initialize the language here
and it will work
Answered By - Ajaya Tiwari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.