【问题标题】:loading local html file in local language in webview in android在android的webview中以本地语言加载本地html文件
【发布时间】:2016-03-30 06:27:14
【问题描述】:

我正在为农民开发一个 android 信息应用程序。信息将以当地印度语言提供。我为此目的使用 webview。信息存储在 html 文件中。问题是本地语言的信息不是可见。如何解决?

WebView mWebView;

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

    // Getting reference to WebView of the activity_main layout
    mWebView = (WebView) findViewById(R.id.webview);

    // Loading an html page into webview
    mWebView.loadUrl("file:///android_asset/text.html");
}

活动主要

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res   /android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".MainActivity" >

    <WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/hello_world" />

    </RelativeLayout>

html文件

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;" charset="UTF-8">
    <style>
    /** Specify a font named "MyFont",
    and specify the URL where it can be found: */
     @font-face {
                font-family: "MyFont";
                src: url('file:///android_asset/b.ttf');
            }
            h3 { font-family:"MyFont"}
        </style>
</head>
<body>
    <h3>
        ಪ್ರಶಾಂತ
    </h3>
</body>

【问题讨论】:

  • text-xy.html 这样存储您的文件,其中 xy 类似于 enin、... 一个 2 字符短表示语言。然后,根据当前的语言环境,加载相应的文件。

标签: android


【解决方案1】:

您的意思是说您想以地区语言显示 helloworld。为此,您需要创建 res/values- 文件夹。 android 框架会自动选择正确的语言 细节: http://developer.android.com/guide/topics/resources/localization.html

【讨论】:

    【解决方案2】:

    以下是一些可能对您有所帮助的 stackoverflow 帖子。

    How to show local languages font.

    How to use custom font with webview.

    【讨论】:

      【解决方案3】:
      Try this
      
      add this statement to your onCreate().
      
      mWebView.getSettings().setJavaScriptEnabled(true);
      
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      
          // Getting reference to WebView of the activity_main layout
          mWebView = (WebView) findViewById(R.id.webview);
      
          mWebView.getSettings().setJavaScriptEnabled(true);
      
          // Loading an html page into webview
          mWebView.loadUrl("file:///android_asset/text.html");
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-19
        • 2014-02-28
        • 2022-06-25
        • 2011-05-31
        • 1970-01-01
        • 1970-01-01
        • 2020-01-16
        • 1970-01-01
        相关资源
        最近更新 更多