【发布时间】:2015-09-06 19:47:52
【问题描述】:
朋友们注意到我的页面加载了 webview,但是当您单击链接时,它会打开导航,而我只想在 webview 中加载,我需要帮助吗?
我做了以下项目:
http://karthiktechfreak.blogspot.com.br/2015/07/profesional-android-webview-application.html
【问题讨论】:
朋友们注意到我的页面加载了 webview,但是当您单击链接时,它会打开导航,而我只想在 webview 中加载,我需要帮助吗?
我做了以下项目:
http://karthiktechfreak.blogspot.com.br/2015/07/profesional-android-webview-application.html
【问题讨论】:
我不完全确定您的问题是什么,但这里有一个可以运行的 Webview 应用程序。
主活动
public class MainActivity extends Activity{
WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startWebView();
//Now, use webView.loadUrl(String url) whenever you want to load a website
}
void startWebView(){
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
activity_main.xml
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
【讨论】: