第九章,WebView点击网页内链接跳转到其他Activity(Android)
来源:互联网 发布:淘宝网迪奥香水 编辑:程序博客网 时间:2024/04/30 06:56
在 AndroidManifest.xml中添加网络权限
<uses-permission android:name="android.permission.INTERNET"/>activity_main.xml
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <Button android:id="@+id/main_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="start" /> <WebView android:id="@+id/main_web" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>MainActivity.java
package com.example.webviewdemo01;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.webkit.WebChromeClient;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Button;public class MainActivity extends Activity implements OnClickListener {private Button main_button;private WebView web_view;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 初始化数据initView();}private void initView() {// TODO Auto-generated method stubmain_button = (Button) this.findViewById(R.id.main_button);web_view = (WebView) this.findViewById(R.id.main_web);// 设置监听main_button.setOnClickListener(this);}@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubweb_view.loadUrl("http://www.baidu.com");// WebChromeClienty用来处理WebView的Javascript的对话框、// 网站图标、网站title、加载进度等,重写里面的方法即可web_view.setWebChromeClient(new WebChromeClient());// 此方法此处可不写// WebViewClient用来处理WebView各种通知、请求事件等,重写里面的方法即可web_view.setWebViewClient(new WebViewClient() {// 点击页面中的链接会调用这个方法@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {// TODO Auto-generated method stub// 跳转到另外的activityIntent intent = new Intent(getApplication(),SecondActivity.class);startActivity(intent);Log.i("qing", "shouldOverrideUrlLoading..." + url);return super.shouldOverrideUrlLoading(view, url);}});}}运行截图:
点击上面任何一个链接
注:第二个activity的代码和布局因为没写太多内容,这里就没有贴出。
0 0
- 第九章,WebView点击网页内链接跳转到其他Activity(Android)
- Android内嵌网页webview点击其中的链接跳转到我们应用内的Activity
- Android使用WebView嵌入网页,网页内点击跳转到另一个网页后,返回问题解决
- webview中实现当点击网页中的按钮的时候,跳转到本地的activity。
- Android---webview实现网页的点击跳转
- Activity设置android:windowIsTranslucent属性之后,点击按钮跳转到其他的Activity
- Android 控件之点击链接跳转Activity
- 5+webview跳转到Android原生activity
- UITextView设置超链接,点击跳转到应用内的webView
- WebView点击里面的按钮跳转到Activity
- [Phonegap+Sencha Touch] 移动开发58 从移动浏览器(或webview)网页上点击链接跳转到QQ聊天界面
- intent://platformapi/startapp?--Webview内跳转到支付宝网页
- (android)点击Button跳转到不同Activity
- 点击列表跳转网页(webView)
- Android点击按钮跳转到网页
- android:WebView在没有网络情况下,点击当前页面内链接不跳转并弹出提示框
- Android Activity之间跳转及跳转到其他app
- iOS实现在webview页面内点击链接,跳转指定App
- opencv cvZero
- 使用visualvm远程监控java进程(以hadoop进程为例)
- Android开发技巧二--避免在EditText中验证日期
- 有限状态机在管理系统的简单应用
- hadoop性能测试
- 第九章,WebView点击网页内链接跳转到其他Activity(Android)
- MINI2440 TD35 P35触摸屏不能使用? 让我们来把一线触控改四线触控
- Timing Wheel 时间轮算法 java实现
- 字符串补位
- 界面设计感想杂记
- JVM调试命令
- Linux_1.5_makefile工程管理
- iOS错误汇总:解决Xcode iPhone工程变成了My Mac的问题
- Zookeeper 04 异步访问ZooKeeper