1.知识图谱:
1.xml文件
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cookie.android0619intent.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳B"
android:textSize="30sp"
android:onClick="jumpB"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="打电话"
android:onClick="callPhone"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="百度一哈"
android:onClick="baidu"/>
</LinearLayout>
activity_b.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cookie.android0619intent.BActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是洒家的浏览器"
android:textSize="30sp"
android:background="#6600"/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wv_web"
></WebView>
</LinearLayout>
JAVA代码:
MainActivity.java
package com.example.cookie.android0619intent;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void jumpB(View view){
//显式Intent
Intent intent=new Intent();
//设置要跳转的组件的名字
ComponentName componentName=new ComponentName(this,BActivity.class);
intent.setComponent(componentName);
startActivity(intent);
//隐式Intent
}
public void callPhone(View view){
Intent intent=new Intent();
//跳到一个视图
intent.setAction(Intent.ACTION_VIEW);
//指定数据
intent.setData(Uri.parse("tel:13539407043"));
startActivity(intent);
}
public void baidu(View view){
Intent intent=new Intent();
//跳一个系统的视图
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
}
}
BActivity.java
package com.example.cookie.android0619intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class BActivity extends AppCompatActivity {
private WebView wv_web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
wv_web = (WebView) findViewById(R.id.wv_web);
//接收main页面界面传递过来的数据(网址)
String path=getIntent().getDataString();
//让wv_web加载网址
wv_web.loadUrl(path);
//设置使用自己的wv_web客户端打开网址
wv_web.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
}