Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android的webview中加载本地语言的本地html文件_Android - Fatal编程技术网

在android的webview中加载本地语言的本地html文件

在android的webview中加载本地语言的本地html文件,android,Android,我正在为农民开发一个android信息应用程序。信息将以当地的印度语言提供。我正在使用webview。信息存储在html文件中。问题是当地语言的信息不可见。如何解决这个问题 WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main

我正在为农民开发一个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>

/**指定名为“MyFont”的字体,
并指定可在其中找到它的URL:*/
@字体{
字体系列:“MyFont”;
src:url('file:///android_asset/b.ttf');
}
h3{font系列:“MyFont”}
ಪ್ರಶಾಂತ

你的意思是说你想用地区语言展示helloworld。为此,您需要创建res/values-folder。android框架将自动选择正确的语言 细节:

下面是两个stackoverflow帖子,可能会对您有所帮助


text xy.html
那样存储文件,其中xy类似于
en
中的
。。。表示语言的两个字符的短字符。然后,根据当前区域设置加载相应的文件。
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");
}