【问题标题】:set the text direction in WebView to RTL将 WebView 中的文本方向设置为 RTL
【发布时间】:2017-06-30 14:15:17
【问题描述】:

如何在 webview 中将文本方向更改为从右到左?

这是我的代码

WebView web = (WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL("", myhtml, "text/html", "UTF-8", "");

【问题讨论】:

    标签: android webview text-align


    【解决方案1】:

    我认为您需要更改 HTML 代码中的 dir="RTL。 例如:

    <body dir="rtl">
       <p>Some Text that will be RTL aligned</p>
    </body>
    

    WebView 仅允许您查看网页,但不会更改文本方向。这仅取决于网页中的 HTML 标记。

    如果仍然无法正常工作,则您的 HTML 可能存在问题。您可以在这里分享您的代码,我可以进一步帮助您。

    汤姆。

    【讨论】:

      【解决方案2】:

      它对我有用:

      desc.loadDataWithBaseURL("http://www.atfonline.ir/", "<html dir=\"rtl\" lang=\"\"><body>" + outhtml + "</body></html>", "text/html", "UTF-8", null);
      

      【讨论】:

      • 什么是 desc?什么是outhtml?
      • @PrajwalW descWebview 对象,在第一个问题中是 web
      猜你喜欢
      • 1970-01-01
      • 2018-07-03
      • 2020-11-18
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多