您的位置:首页 > 本地本地

webview加载assets中的html内容显示不出来,为啥

admin2024-05-01人已围观

一、webview加载assets中的html内容显示不出来,为啥

语法写正确没滚友蠢,比如

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

webView = (WebView) findViewById(R.id.webView);

webView.loadUrl(file///android_asset/index.html);

}

webView.loadUrl(file:///android_asset/index.html);

少了个冒大陪号也显示不告裂出来,这是我亲身体会过的

要是语法正确,那就看看自己的代码写对没

语法写正确没滚友蠢,比如

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

webView = (WebView) findViewById(R.id.webView);

webView.loadUrl(file///android_asset/index.html);

}

webView.loadUrl(file:///android_asset/index.html);

少了个冒大陪号也显示不告裂出来,这是我亲身体会过的

要是语法正确,那就看看自己的代码写对没

二、ios如何加载本地文件

1,本地的段改html文件一定要放到工程文件的根衫正目录

2,html代码中的图片路径一定要是相对路径

3,下面是用UIWebView调用本地文件的方法握塌判

方法一:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@1 ofType:@html];

NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]

[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

方法二:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@1 ofType:@html];

NSURL *url = [NSURL fileURLWithPath:filePath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:request];

[self.view addSubview:myWebView];

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@plistdemo ofType:@plist];

NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];

NSLog(@%@, data);//直谨裤接打印数据。

上纳仔面为plist文件读取示例洞晌汪

三、如何通过Html网页调用本地安卓app

1、首先在编写一个简单态陪闭的html页面。

2、在Android本地app的配置

示例截图如帆裂下:

然后使用“手机浏览器”或者“webview”乱锋的方式打开这个本地的html网页,点击“打开APP”即可成功开启本地的指定的app。

四、怎么在webview中访问本地js文件

建议你把html代码保存成文件和js文件都放到asset里,这样你引用js就可以用相对路径。然后通过webView.loadUrl(file:///android_asset/XX.html)加载html。

很赞哦! ()

上一篇:关于git如何将老仓库中的分支迁移到新仓库中'>谈谈自媒体、新媒体和融媒体

下一篇:返回列表'>返回列表

随机图文