Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio how to make WebView supports to the Arabic Language i.e., RTL text Direction?

I am using webview in android to display terms and conditions , but the issue is I need to make application supports for Arabic language. Here it required make the text direction Right to Left (RTL). But I followed lot ways to solve this. Can you please check the ways and suggest me once.

Process One

private String mUrl="terms_conditions_url";

WebView webview=findViewById(R.id.web_view);



if(ltrDirection){

/** For LTR text */

webView.loadData(mUrl);

}else{

/** For RTL text */

 mWebView.loadDataWithBaseURL(mURL,"<html><body dir=\"rtl\"></body></html>", "text/html", "UTF-8", null);

}

Process Two And also I followed another way it is like..,

private String mUrl="terms_conditions_url";

WebView webview=findViewById(R.id.web_view);


if(ltrDirection){

/** For LTR text */

webView.loadData(mUrl);

}else{

/** For RTL text */

 mWebView.loadDataWithBaseURL(mURL,"<html dir=\"rtl\"></html>", "text/html", "UTF-8", null);

}

But nothing is worked for me.

Please give me the best code for it.

like image 770
sreeku24 Avatar asked Dec 14 '25 14:12

sreeku24


1 Answers

Use this code! updated!

    WebView wv;
        String outhtml = "Terms and Condition are as follows....your strings";

     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            wv = (WebView) findViewById(R.id.web_test);
    wv.loadDataWithBaseURL(mURL, "<html dir=\"rtl\" lang=\"\"><body>" + outhtml + "</body></html>", "text/html", "UTF-8", null);
like image 76
Prajwal Waingankar Avatar answered Dec 17 '25 09:12

Prajwal Waingankar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!