android - 网络应用程序在安装和打开时出现黑屏?
问题描述
我是 android 的新手,正在尝试通过遵循教程制作 webapp。
但是,当安装一个签名的 apk 时,打开它会给出一个空白页面。不知道出了什么问题。
我编辑的页面是:
活动主:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
tools:context=".MainActivity">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>
安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iinfohub.www.iinfohub">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="IINFO HUB"
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.iinfohub.www.iinfohub;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView mWebView;
SwipeRefreshLayout swipe;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
public void onRefresh() {
LoadWeb();
}
});
LoadWeb();
}
public void LoadWeb() {
mWebView = (WebView) findViewById(R.id.webView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.loadUrl("http://iinfohub.com/forapp/index.php");
swipe.setRefreshing(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onReveivedError(WebView view, int errorCode, String description, String failingUrl) {
mWebView.loadUrl("file://android_asset/error.html");
}
public void onPageFinished(WebView view, String url) {
//hide the swipe refreshlayout
swipe.setRefreshing(false);
}
});
}
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
我所做的只是按照该教程进行操作,正如我所提到的,它提供了一个运行签名 APK 的空白页面。
非常感谢您对此的任何帮助。
解决方案
我认为你应该loadUrl
毕竟。因为设置/配置必须在加载页面之前应用。
推荐阅读
- macos - MacOS - 一行命令在终端中工作,但不在 .sh 脚本中?
- sql - SQL Select 语句,使用 convert 将 Format mmddyy 更改为 dd-mon-yyyy
- javascript - 使用 Node.js 和 JavaScript 从缓冲区渲染 PDF
- python - 递归算法在这个片段中是如何工作的?
- angular - 为什么在 Reactive Form 上插值不返回任何值?
- javascript - Javascript onsubmit 不返回任何值,如 true 或 false。表单无需验证即可提交
- java - 如何在 Flink Kafka Consumer 中动态获取正在处理的 kafka 主题名称?
- android - 构建 Android 库时集成现有 Android 库的问题
- bash - 530 登录错误,使用 lftp 时
- powerbi - PowerQuery 编辑器在我的表上抛出一个错误