Android studio点击跳转WebView详解
作者:飞鸟96 时间:2022-12-12 05:11:17
本文实例为大家分享了Android studio点击跳转WebView的具体代码,供大家参考,具体内容如下
代码文件
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private StringBuffer sb;/*截取字符串*/
private TextView tv1;
private WebView webv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*获取文字的ID*/
tv1=(TextView)findViewById(R.id.wang);
/*获取网页控件的ID*/
webv=(WebView)findViewById(R.id.web);
/*new一个字符串*/
sb=new StringBuffer("http://www.baidu百度百度.com");
/*删除包含16 不包含20的字符串*/
sb.delete(16,20);
/*把截取的字符串写入文字id里*/
tv1.setText(sb);
/*文字点击事件*/
tv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webv.getSettings().setJavaScriptEnabled(true);
webv.loadUrl("https://www.baidu.com");
/*网页*/
webv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
});
}
});
}
}
页面布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="你的包名地址.MainActivity">
<TextView
android:id="@+id/wang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www.baidu.com"
android:layout_centerHorizontal="true"
/>
<RelativeLayout
android:id="@+id/l1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/wang"
android:layout_centerHorizontal="true"
>
<TextView
android:id="@+id/ba"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="百度"
/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_toRightOf="@id/ba"
/>
<TextView
android:id="@+id/yu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="百度"
android:layout_toRightOf="@id/img"
/>
</RelativeLayout>
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/l1"
>
</WebView>
</RelativeLayout>
来源:http://blog.csdn.net/qq_39493777/article/details/78110143
标签:Android,studio,点击跳转,WebView
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android 中StringBuffer 和StringBuilder常用方法
2023-10-29 08:39:26
Java 实战项目之精美物流管理系统的实现流程
2023-10-30 19:53:46
![](https://img.aspxhome.com/file/2023/8/125248_0s.png)
spring多数据源配置实现方法实例分析
2023-06-06 22:15:56
java8 stream多字段排序的实现
2021-07-30 17:47:47
android系统在静音模式下关闭camera拍照声音的方法
2021-09-04 00:34:20
![](https://img.aspxhome.com/file/2023/7/137207_0s.gif)
Java中的 FilterInputStream简介_动力节点Java学院整理
2023-01-21 17:18:56
Java实时获取基金收益项目源码分享
2023-11-28 17:30:47
![](https://img.aspxhome.com/file/2023/4/85894_0s.png)
详解SpringMVC和MyBatis框架开发环境搭建和简单实用
2022-03-11 13:54:51
![](https://img.aspxhome.com/file/2023/8/118818_0s.png)
详解Spring整合Ehcache管理缓存
2022-02-10 00:50:17
android BitmapFactory.Options使用方法详解
2023-05-04 08:50:20
Java实现画线、矩形、椭圆、字符串功能
2022-12-30 19:24:33
![](https://img.aspxhome.com/file/2023/0/72590_0s.jpg)
SpringBoot搭建go-cqhttp机器人的方法实现
2022-11-17 23:58:40
![](https://img.aspxhome.com/file/2023/2/134022_0s.png)
C#异步调用示例详解
2023-09-12 13:02:04
Android+SQLite数据库实现的生词记事本功能实例
2023-06-18 10:41:35
java GUI编程之监听操作实例分析
2022-09-28 05:55:53
基于web项目log日志指定输出文件位置配置方法
2021-10-04 09:25:27
![](https://img.aspxhome.com/file/2023/7/83037_0s.jpg)
C#判断访问来源是否为搜索引擎链接的方法
2021-11-01 09:15:53
列举java语言中反射的常用方法及实例代码
2022-10-31 13:45:07
再议C#中的装箱与拆箱的问题详解
2022-09-30 03:45:40
Android编程之SMS读取短信并保存到SQLite的方法
2022-01-30 18:02:45
![](https://img.aspxhome.com/file/2023/3/139003_0s.png)