1

我刚刚安装了 phonegap 并且是新手。我在 android 文件夹下导入了示例并运行它,它似乎正确显示了底层文件。但是,如何导入我的 html/js 文件。我试图在网上查找,但到目前为止没有运气。如何在 phonegap 中为 webview 创建一个项目并同时导入我的 js/html 文件。我是否还必须在 android 中为相同的代码或 phone gap 为我做所有事情?

4

1 回答 1

0

您必须将 html、js 和 css 文件放在 assets 文件夹中。

在主要活动中,您对它们的引用如下:

super.loadUrl("file:///android_asset/www/index.html");

根据PhoneGap 文档 - Android 入门

编辑

关于格式化和使其适合屏幕将取决于您处理 html、css 和 js 文件的方式。例如,这是一个 html 文件,它独立于屏幕方向和屏幕大小来适应屏幕:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <title>Hello World</title>
    </head>
    <body>
            <h1>Apache Cordova</h1>
                <div>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.</div>
    </body>
</html>

我所做的是总结原始科尔多瓦的 html,它在应用程序上完美运行。

有关格式化的更多信息,请在应用程序启动并运行后参考网页设计问题而不是 PhoneGap。

于 2013-09-05T16:39:07.483 回答