如何在我的应用程序中打开网页? [英] How To Open Web Page Within My App?
问题描述
这是我在这里的第一个问题.我知道之前有人问过这个问题,但我没有找到真正解释像我这样的新手的答案/解决方案.
This is my first question here. I know that this question has been asked before, but I didn't find an answer/solution that really explains the answer for a totally newbie like me.
我正在创建一个带有许多按钮的线性布局的应用程序,每个按钮都应该将用户引导到不同的网页.按钮运行良好,每个按钮都转到其特定的网页,但在默认浏览器中,而不是在应用程序中.
I am creating an app with a linear layout that has a lot of buttons, each button should drive the user to a different web page. The buttons works well and every buttons goes to its specific web page, but in the default browser, not within the app.
这是我的 webview.xml 文件:
This is my webview.xml file:
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
这是 WebViewActivity.java 文件:
This is the WebViewActivity.java file:
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(
"http://egy-tech-droid.blogspot.com.eg/search/label/%D8%AA%D8%B7%D8%A8%D9%8A%D9%82%D8%A7%D8%AA%20%D8%AD%D8%B5%D8%B1%D9%8A%D8%A9");
}
我在清单文件中添加了互联网权限:
I added the internet permission in the Manifest file:
<uses-permission android:name="android.permission.INTERNET" />
这会在设备的默认浏览器中打开网页,我希望它在我的应用程序中打开.有什么帮助吗?(请给我一个详细的答案/解释)
This opens the web page but in the default browser of the device and I want it to open inside my app. Any help? (please give me a detailed answer/explanation)
推荐答案
将此添加到您的代码中
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
这篇关于如何在我的应用程序中打开网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!