WebView的使用(1)
2016-07-18 11:34
218 查看
直接使用WebView加载uri, 会出现,调用系统的浏览器来访问uri
package com.example.webviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
//如果直接加在uri
webView.loadUrl("http://www.baidu.com");
}
}
主布局:
<span style="font-size:18px;"><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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<WebView
android:layout_below="@+id/textView1"
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/textView1" />
</RelativeLayout></span>来看一下效果:
使用WebView自己的加载方式:
看下效果:并没有调用浏览器来加载uri,而是WebView自己的
加载方式。 可以看到哦uri数据显示在webView中,而不是在浏览器中。
package com.example.webviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
//如果直接加在uri
webView.loadUrl("http://www.baidu.com");
}
}
主布局:
<span style="font-size:18px;"><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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<WebView
android:layout_below="@+id/textView1"
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/textView1" />
</RelativeLayout></span>来看一下效果:
使用WebView自己的加载方式:
看下效果:并没有调用浏览器来加载uri,而是WebView自己的
加载方式。 可以看到哦uri数据显示在webView中,而不是在浏览器中。
相关文章推荐
- WebView的使用 (全)
- WebView的使用
- Android 使用webview遇到的问题及解决办法
- Android常用Manager
- ue4类似unity多相机分屏与小地图效果实现教程
- Android Studio 生成javadoc
- iOS-上传 包的时候 提示 Redundant binary upload
- 百度移动端首页前端速度那些事儿
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
- iOS 图标适配官网
- Android自定义ListView实现下拉刷新
- 为什么图片加载我首先Glide
- CocoaPods详解——安装和使用以及可能遇到的错误
- ViewPager源码解析
- HoloLens开发手记 - Unity之Keyboard input 键盘输入
- rxjava + rxandroid 调度器
- Android 开机自启或干其他事情
- Android 绘图(二) Canvas
- 一个千万量级的APP使用的一些第三方库
- Unity官方文档之“图形性能优化-帧调试器”的翻译