【发布时间】:2019-05-17 23:06:38
【问题描述】:
我想创建一个 localhost 网站或非在线网站的 web 视图,我该怎么做它选择在线网站链接而不是 localhost 有没有办法做到这一点?
我尝试使用 localhost 和 ip 提供链接,但它没有选择我的网站。
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview = findViewById(R.id.webview);
WebSettings webSettings = mywebview.getSettings();
webSettings.getJavaScriptEnabled();
mywebview.loadUrl("http://192.000.00.0/traveland/index.php");
mywebview.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed()
{
if(mywebview.canGoBack())
{
mywebview.goBack();
}
else
{
super.onBackPressed();
}
}
}
MainActivity.xml
<RelativeLayout 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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"
android:id="@+id/webview"/>
</RelativeLayout>```
It shows all the online websites not the offline ones how can that be done?
【问题讨论】:
-
如果是本地网站,为什么不将其存储在本地,然后存储在 Android 设备上?而不是那个 IP,因为如果在 Google 上发布它,没有人将能够访问,因为他们不在网络中
标签: android localhost android-webview